检查jenkins管道中是否存在文件 [英] Check if a file exists in jenkins pipeline

查看:1732
本文介绍了检查jenkins管道中是否存在文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的jenkins工作空间中存在目录,并且工作空间中的管道步骤 "fileExists:验证文件存在" ,我尝试运行块正确.

I am trying to run 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 pipeline?

推荐答案

if条件下使用fileExists步骤时,需要使用方括号,或者将返回值分配给变量

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'
}

这篇关于检查jenkins管道中是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆