我在Windows机器上运行Jenkins。 如何将%BUILD_NUMBER%等环境变量传递给下游作业? 我正在使用下面的代码,但是没有按预期工作,它在输出中再次打印相同的东西
build job: 'DeployBuild', parameters: [string(name: 'BuildId', value: $env:BUILD_NUMBER)], wait: false
我得到的输出:
C:\JenkinsBuilds\jobs\DeployBuild\workspace>echo $env:BRANCH_NAME-$env:BUILD_NUMBER
$env:BRANCH_NAME-$env:BUILD_NUMBER
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
预期产出:
C:\JenkinsBuilds\jobs\DeployBuild\workspace>echo TESTJob-12
TESTJob-12
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
尝试过多个模式,例如$ {BUILD_NUMBER},$ BUILD_NUMBER%BUILD_NUMBER,但没有人提供预期的输出。
答案 0 :(得分:0)
您可以尝试发送env.BUILD_NUMBER或“$ {BUILD_NUMBER}”或“env.BUILD_NUMBER”,并注意双引号字符串插值仅适用于双引号。
答案 1 :(得分:0)
将value: $env:BUILD_NUMBER)
设为value: ${env.BUILD_NUMBER}
。这样做。总代码如下:
build job: 'DeployBuild', parameters: [string(name: 'BuildId', value: ${env.BUILD_NUMBER})], wait: false