我有两组多阶段作业,parallel test 1
和parallel test 2
;我需要同时执行两个组。
multi job
jenkins插件对此有黑客吗?或任何其他选择...
注意:我不希望同一MultiJob Phase
上的所有3个工作
答案 0 :(得分:1)
由于您不能在一个多作业阶段中运行这些作业,因此可以选择使用Jenkins管道作业(Pipeline docs)。可以通过使用声明式管道parallel
块来实现并行阶段的执行。一个如何通过管道实现MultiJob的虚拟示例:
pipeline {
agent any
stages {
stage('MultiJob like stage') {
parallel {
stage('Parallel Test') {
steps {
echo "Here trigger job: allure_behave. Triggered at time:"
sh(script: "date -u")
// build(job: "allure_behave")
}
}
stage('Parallel Test 2') {
steps {
echo "Here trigger job: allure_behave_new. Triggered at time:"
sh(script: "date -u")
// build(job: "allure_behave_new")
echo "Here trigger job: allure_behave_old. Triggered at time:"
sh(script: """date -u""")
// build(job: "allure_behave_old")
}
}
}
}
}
}
在这种情况下,您有一个名为MultiJob like stage
的阶段,该阶段具有子阶段Parallel Test
和Parallel Test 2
,就像在MultiJob中一样。区别在于,这两个子阶段都是并行执行的。
要从管道作业内部触发其他作业,请使用build
步骤:
build(job: "job-name")
或者,如果您需要使用参数来运行它,则只需添加parameters
build()
选项:
build(job: "${JOB_NAME}", parameters: [string(name: 'ENVNAME', value: 'EXAMPLE_STR_PARAM')])
蓝海景观:
输出:
Running on Jenkins in /var/jenkins_home/workspace/Dummy_pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (MultiJob like stage)
[Pipeline] parallel
[Pipeline] { (Branch: Parallel Test)
[Pipeline] { (Branch: Parallel Test 2)
[Pipeline] stage
[Pipeline] { (Parallel Test)
[Pipeline] stage
[Pipeline] { (Parallel Test 2)
[Pipeline] echo
Here trigger job: allure_behave. Triggered at time:
[Pipeline] sh
[Pipeline] echo
Here trigger job: allure_behave_new. Triggered at time:
[Pipeline] sh
+ date -u
Thu Nov 22 18:48:56 UTC 2018
+ date -u
Thu Nov 22 18:48:56 UTC 2018
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] echo
Here trigger job: allure_behave_old. Triggered at time:
[Pipeline] sh
+ date -u
Thu Nov 22 18:48:56 UTC 2018
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // parallel
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
此替代方法是否对您的用例有效?
致谢