我有一份工作,需要知道上一份工作计算的价值.
有没有办法将它存储在Hudson/Jenkins环境中?
例如,我可以在shell脚本操作中编写类似下一个内容:
XXX=`cat /hardcoded/path/xxx`
#job itself
echo NEW_XXX > /hardcoded/path/xxx
Run Code Online (Sandbox Code Playgroud)
但是有更可靠的方法吗?
Eam*_*nne 12
一些选择:
userContent你可以使用的子目录 - 这样文件至少是jenkins安装的一部分,因此更容易迁移或备份.我为我的构建的(相当大的)代码覆盖趋势文件执行此操作.适当的解决方案取决于您的情况.
如果您使用管道并且变量是简单类型,则可以使用参数在同一作业的运行之间存储它。
使用该properties步骤,您可以在管道内配置参数及其默认值。配置完成后,您可以在每次运行开始时读取它们,并在最后保存它们(作为默认值)。在声明性管道中,它可能看起来像这样:
pipeline {
agent none
options {
skipDefaultCheckout true
}
stages {
stage('Read Variable'){
steps {
script {
try {
variable = params.YOUR_VARIABLE
}
catch (Exception e) {
echo("Could not read variable from parameters, assuming this is the first run of the pipeline. Exception: ${e}")
variable = ""
}
}
}
}
stage('Save Variable for next run'){
steps {
script {
properties([
parameters([
string(defaultValue: "${variable}", description: 'Variable description', name: 'YOUR_VARIABLE', trim: true)
])
])
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4104 次 |
| 最近记录: |