[英]Trigger Multibranch Job from another
I have a job in Jenkins and I need to trigger another one when it ends (if it ends right).我在 Jenkins 有一份工作,我需要在它结束时触发另一个工作(如果它结束的话)。
The second job is a multibranch, so I want to know if there's any way to, when triggering this job, pass the branch I want to.第二个工作是多分支,所以我想知道在触发这个工作时是否有任何方法可以通过我想要的分支。 For example, if I start the first job in the branch develop, I need it to trigger the second one for the develop branch also.例如,如果我在开发分支中开始第一个工作,我需要它来触发开发分支的第二个工作。
Is there any way to achieve this?有什么办法可以做到这一点?
Just think about the multibranch job being a folder containing the real jobs named after the available branches: 考虑一下多分支作业是一个包含以可用分支命名的实际作业的文件夹:
When using the pipeline build step you'll have to use something like: build(job: 'JOB_NAME/BRANCH_NAME')
. 使用管道构建步骤时,您将必须使用类似于: build(job: 'JOB_NAME/BRANCH_NAME')
。 Of course you may use a variable to specify the branch name. 当然,您可以使用变量来指定分支名称。
When triggering from a Freestyle job you most probably have to 从Freestyle作业触发时,您最有可能必须
JOB_NAME/BRANCH_NAME
作为工作名称,请使用与上述相同的模式: JOB_NAME/BRANCH_NAME
Should be possible to use a job parameter to specify the branch name here. 应该可以在此处使用job参数指定分支名称。 However I didn't give it a try, though. 但是,我没有尝试。
Yes, you can call downstream job by adding post build step: Trigger/Call build on other projects(you may need to install "Parameterized Trigger Plugin"): 是的,您可以通过添加后期构建步骤来调用下游作业:在其他项目上触发/调用构建(您可能需要安装“ Parameterized Trigger Plugin”):
Also multibranch_PARAM1 and *PARAM2 must be configured in the downstreamjob: 此外,还必须在下游作业中配置multibranch_PARAM1和* PARAM2:
Sometimes you want to call one or more subordinate multibranch jobs and have them build all of their branches, not just one.有时你想调用一个或多个从属的多分支作业,让他们建立所有的分支,而不仅仅是一个。 A script can retrieve the branch names and build them.脚本可以检索分支名称并构建它们。
Because the script calls the Jenkins API<\/a> , it should be in a shared library to avoid sandbox restrictions.因为脚本调用了Jenkins API<\/a> ,所以它应该在一个共享库中以避免沙盒限制。 The script should clear non-serializable<\/a> references before calling the build step.该脚本应在调用构建步骤之前清除不可序列化的<\/a>引用。
def callMultibranchJob(String name) {
def item = jenkins.model.Jenkins.get().getItemByFullName(name)
def jobNames = item.allJobs.collect {it.fullName}
item = null // CPS -- remove reference to non-serializable object
for (jobName in jobNames) {
build job: jobName
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.