【问题标题】:fileExists in jenkins pipeline not working with ${variant}詹金斯管道中的文件存在不适用于 ${variant}
【发布时间】:2021-05-19 00:16:29
【问题描述】:

在詹金斯管道中

变量是从作业配置中读取的

variant = job_config['variant']

variant 可以是“abc”或“xyz”,具体取决于作业配置中输入的内容。

if(fileExists('tmp/build/${variant}/bin/Test.xml'))
{
echo "Test.xml exists" 
}
else
{
echo "Test.xml doesnot exists" 
}

让我们假设变量在作业配置中被指定为“abc”。 即使 'tmp/build/abc/bin/Test.xml' 真实存在,

在 jenkins 构建期间,'tmp/build/${variant}/bin/Test.xml 的条件检查文件存在按原样读取,即 ${variant} 不替换为 abc 在条件检查期间。

你能帮忙解决这个问题吗?谢谢!

【问题讨论】:

    标签: jenkins jenkins-pipeline file-exists


    【解决方案1】:

    您可能需要在路径中使用双引号而不是单引号: if(fileExists("tmp/build/${variant}/bin/Test.xml")) 以便将变量替换为其值。

    Jenkins 管道是用 groovy 编写的,因此您可以在 this question 和 the official groovy documentation 中找到有关 groovy 中单引号和双引号之间区别的更多信息。

    【讨论】:

      猜你喜欢
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 2019-02-27
      • 2016-11-26
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 2019-01-09
      相关资源
      最近更新 更多