如何触发另一个需要$ BRANCH变量的Jenkins管道? [英] How to trigger another Jenkins pipeline that needs a $BRANCH variable?
问题描述
我有3条管道.说:
build-and-release
build
release
我正在重构管道,以便可以从build-and-release
内部调用build
和release
作业.遵循以下原则:
I'm refactoring my pipelines, so that I can just call the build
and release
jobs, from within the build-and-release
. Something along these lines:
// build-and-release JenkinsFile
node('master') {
build job: "build", propagate: true, wait: true
build job: "release", propagate: true, wait: true
}
// build JenkinsFile
node('master') {
stage('Build') {
// do stuff
}
}
// release JenkinsFile
node('master') {
stage('Release') {
// do other stuff
}
}
这似乎按原样工作,但是build
和release
管道始终假定分支为MASTER.运行build-and-release
作业时,选择要构建的分支.
This seems to work as it is, but the build
and release
pipelines always assume the branch is MASTER. When I run the build-and-release
job, I pick what branch I want to build.
如何使其他作业使用从build-and-release
中选择的相同$ BRANCH?
How do I make the other jobs use the same $BRANCH that I pick from build-and-release
?
推荐答案
您可以将build
和release
作业配置为参数化作业,然后可以将分支名称作为参数发送,如下所示:->
You can configure build
and release
jobs as parameterized job and then you can send the Branch name as a prameter, as shown below:-
// build-and-release JenkinsFile
node('master') {
build job: 'build', parameters: [string(name: 'Branch', value: "${env.BRANCH_NAME}")], propagate: true, wait: true
build job: 'release', parameters: [string(name: 'Branch', value: "${env.BRANCH_NAME}")], propagate: true, wait: true
}
然后您可以在构建和发布的Jenkinsfile中使用 Branch 变量.
And then you can use the Branch variable in Jenkinsfile of build and release.
注意:-您可以在上面的示例中配置任何其他参数类型字符串参数已配置,有关更多信息,请参考
Note:- You can configure any other parameter type in above example String Parameter has been configured, for more information please refer the link
这篇关于如何触发另一个需要$ BRANCH变量的Jenkins管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!