检查詹金斯管道中是否存在文件
问题描述:
如果我的 jenkins 工作区中存在目录,并且工作区中的管道步骤 fileExists:验证文件存在" 似乎没有,我正在尝试运行一个块正常工作.
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 doesn't seem to work correctly.
我使用的是 Jenkins v 1.642 和 Pipeline v 2.1.并试图拥有像
I'm using Jenkins v 1.642 and Pipeline v 2.1. and trying to have a condition like
if ( fileExists 'test1' ) {
//Some block
}
我在管道中还有哪些其他选择?
What are the other alternatives I have within the pipeline?
答
使用fileExists
在 if
条件中执行步骤或分配返回值到一个变量
You need to use brackets when using the fileExists
step in an if
condition or assign the returned value to a variable
使用变量:
def exists = fileExists 'file'
if (exists) {
echo 'Yes'
} else {
echo 'No'
}
使用括号:
if (fileExists('file')) {
echo 'Yes'
} else {
echo 'No'
}