简体   繁体   English

如何将环境变量传递给jenkinsfile的下游

[英]How to pass environmental variables to downstream from jenkinsfile

I am running Jenkins on a windows machine. 我在Windows机器上运行Jenkins。 How can I pass environment variables like %BUILD_NUMBER% to a downstream job? 如何将%BUILD_NUMBER%之类的环境变量传递给下游作业? I am using below piece of code but that is not working as expected, it is printing the same thing again in output 我正在使用下面的代码,但是没有按预期工作,它在输出中再次打印了同样的东西

build job: 'DeployBuild', parameters: [string(name: 'BuildId', value: $env:BUILD_NUMBER)], wait: false

The output I am getting: 我得到的输出:

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

Expected Output: 预期产量:

C:\JenkinsBuilds\jobs\DeployBuild\workspace>echo TESTJob-12
TESTJob-12
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Tried multiple patterns like ${BUILD_NUMBER}, $BUILD_NUMBER %BUILD_NUMBER but none is giving the expected output. 尝试了多种模式,例如$ {BUILD_NUMBER},$ BUILD_NUMBER%BUILD_NUMBER,但没有一种模式可提供预期的输出。

您可以尝试发送env.BUILD_NUMBER或“ $ {BUILD_NUMBER}”或“ env.BUILD_NUMBER”,然后注意双引号字符串插值仅发生在双引号中。

Put the value: $env:BUILD_NUMBER) as value: ${env.BUILD_NUMBER} . value: $env:BUILD_NUMBER)放入value: ${env.BUILD_NUMBER} This will do it. 这样就可以了。 So total code will be like: 因此,总代码将如下所示:

build job: 'DeployBuild', parameters: [string(name: 'BuildId', value: ${env.BUILD_NUMBER})], wait: false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将变量从 Jenkinsfile 传递给 shell 命令 - How to pass variables from Jenkinsfile to shell command 如何从父 jenkinsfile 导入子 jenkinsfile 中的 env 变量? - How to import env variables in child jenkinsfile from parent jenkinsfile? 你如何传递字符串变量以在 jenkinsfile 中构建作业参数 - how do you pass string variables to build job parameters in jenkinsfile 如何在詹金斯中将参数作为环境变量从上游作业传递到下游作业? 无需对下游工作进行参数化 - How to pass parameter as environment variable from upstream job to downstream job in jenkins? without downstream jobs being parametrized 从下游作业中获取变量 - getting variables from a downstream job 如何将命令的输出转换为Jenkinsfile中的环境变量? - How can I get the output of a command into an environmental variable in a Jenkinsfile? Jenkins - 我如何将参数从上游传递到下游 - Jenkins - How can i pass parameters from the Upstream to Downstream 如何将输出从上游项目传递到詹金斯的下游项目 - How to pass output from an upstream project to downstream projects in Jenkins 如何通过詹金斯的另一份工作从工作中访问环境变量 - How to access environmental variables from a job by a different job in Jenkins Jenkins-如何将参数从下游作业传递到其父上游? - Jenkins - How to pass parameters from a downstream job to its parent upstream?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM