【发布时间】:2021-07-19 15:33:25
【问题描述】:
我一直在阅读尽可能多的关于此主题的帖子,但没有一篇为我提供可行的解决方案,因此,再次将其扔给社区:
在 Jenkinsfile 管道中我有
steps {
(...)
sh script: '''
$pkgname #existing var
export report_filename=$pkgname'_report.txt'
(stuff is being written to the $report_filename file...)
'''
}
post {
always {
script {
//want to read the file with name carried by $report_filename
def report = readFile(file: env.report_filename, encoding: 'utf-8').trim()
buildDescription(report)
}
}
}
我无法将 report_filename bash var 的值传递给 post > always > 脚本部分。尝试了 ${env.report_filename} (带/不带单引号/双引号),带/不带 env。以及其他一些疯狂的事情。
我在这里做错了什么?
谢谢。
【问题讨论】:
-
你希望 shell 脚本第一行的
$pkgname做什么?变量包含什么? -
export使该变量对 shell 的 children 可用,而不是对父级可用。 -
变量 $pkgname 捕获我刚刚构建的 conda 包的名称(在“步骤”部分中)。然后我构建字符串 {name_of_conda_package}_report.txt 并希望将其存储在 var 报告中以用于后置条件。
-
所以如果变量包含
condapackage.zip,那么只有$pkgname会产生condapackage.zip: no such file or directory。 -
$pkgname 包含一个字符串,例如'a-b-c',我通过report_filename 分配构建了一个报告名称'a-b-c_report.txt',我想在Groovy 中使用report_filename var。跨度>
标签: bash jenkins groovy jenkins-pipeline jenkins-groovy