[英]How to trigger parameterized build on successful build in Jenkins?
I have three pipeline projects, project-a, project-b and project-c. 我有三个管道项目,项目-a,项目-b和项目-c。 project-c takes a parameter. project-c需要一个参数。 On successful completion of either project-a or project-b I want to trigger a build of project-c with a parameter. 成功完成project-a或project-b时,我想触发带有参数的project-c的构建。
I can do this in project-a and project-b with this code in the pipeline: 我可以在项目a和项目b中使用以下代码在管道中执行此操作:
stage('trigger-project-c') {
def job = build job: 'project-c', parameters: [[$class: 'StringParameterValue', name: 'MY_PARAM', value: 'somevalue']]
}
But this requires two executors. 但这需要两名执行者。 I want project-a or project-b to completely finish before running project-c with parameters. 我希望project-a或project-b在使用参数运行project-c之前完全完成。
Your pipeline most likely looks like this: 您的管道很可能看起来像这样:
node {
stage('build') {
// sh "make"
}
// ...
stage('trigger-project-c') {
def job = build job: 'project-c', parameters: [[$class: 'StringParameterValue', name: 'MY_PARAM', value: 'somevalue']]
}
}
By wrapping everything inside the node
closure, the downstream job project-c
is triggered inline, without the upstream job being paused / releasing an executor. 通过将所有内容包装在node
闭包内部,可以内联触发下游作业project-c
,而无需暂停上游作业/释放执行程序。
Therefore, things that do essentially nothing for a long time should not be wrapped within a node
step, in order to not block an executor. 因此,长时间不做任何事情的事情不应包装在node
步骤中,以免阻塞执行程序。 A very similar case is when using the input
step to wait for user feedback . 一个非常相似的情况是使用input
步骤等待用户反馈时 。
Instead, your pipeline should look eg as follows, which is - so to say - the best practice (as you don't block your executor): 取而代之的是,您的管道应如下所示,这就是最佳实践(因为您不会阻塞执行程序):
stage('build') {
node {
// sh "make"
}
}
// or
node {
stage('build') {
// sh "make"
}
stage('unit') {
// sh "make"
}
} // node
// note: the following code is _not_ wrapped inside a `node` step
stage('trigger-project-c') {
def job = build job: 'project-c', parameters: [[$class: 'StringParameterValue', name: 'MY_PARAM', value: 'somevalue']]
}
There is no need to wrap the build
step within a node
, ie, block an executor for it. 无需将build
步骤包装在一个node
,即,为其阻塞执行器。 For other steps (like sh
), pipeline execution would trigger an error and remind you that it cannot be run outside of a node
allocation. 对于其他步骤(如sh
),管道执行将触发错误,并提醒您不能在node
分配之外运行它。
Add the parameter wait: false
to the build
step to continue pipeline execution without waiting for the downstream job. 在build
步骤中添加参数wait: false
,以继续执行管道,而无需等待下游作业。
EDIT: this would help, if you don't care for the success of the other downstream job for this pipeline. 编辑:如果您不关心此管道的其他下游作业的成功,这将有所帮助。 If you need to wait until it is finished and then continue the own (upstream job's) pipeline, then see my other answer. 如果您需要等到完成后再继续自己(上游作业)的管道,请参阅我的其他答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.