Check if a file exists in jenkins pipeline

前端 未结 1 1407
梦毁少年i
梦毁少年i 2020-12-15 02:07

I am trying to run a block if a directory exists in my jenkins workspace and the pipeline step \"fileExists: Verify file exists\" in workspace does

相关标签:
1条回答
  • 2020-12-15 03:05

    You need to use brackets when using the fileExists step in an if condition or assign the returned value to a variable

    Using variable:

    def exists = fileExists 'file'
    
    if (exists) {
        echo 'Yes'
    } else {
        echo 'No'
    }
    

    Using brackets:

    if (fileExists('file')) {
        echo 'Yes'
    } else {
        echo 'No'
    }
    
    0 讨论(0)
提交回复
热议问题