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

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

问题描述

如果我的 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?

推荐答案

使用fileExistsif 条件中执行步骤或分配返回值到一个变量

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

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

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