如何使用多个并行块同时运行多个阶段? [英] How to run multi stages at the same time using multi parallel blocks?
本文介绍了如何使用多个并行块同时运行多个阶段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这里,我需要同时执行Parallel test 1
和Parallel test 2
.
Here, I need to execute both Parallel test 1
and Parallel test 2
at the same time.
当我尝试在其上放置一个并行块时,由于在官方网站Note: that a stage must have one and only one of steps, stages, or parallel
中这样提及,因此它引发了错误.
When I tried to put a parallel block on top of these, it throws an error since it mentioned like this in the official site Note: that a stage must have one and only one of steps, stages, or parallel
.
pipeline {
agent any
stages {
stage('Parallel Test 1') {
parallel {
stage('Block 1 - Stage 1') {
steps {
echo "Block 1 - Stage 1"
build(job: 'jenkins_job_1')
}
}
stage('Block 1 - Stage 2') {
steps {
echo "Block 1 - Stage 2"
build(job: 'jenkins_job_2')
}
}
}
}
stage('Parallel Test 2') {
parallel {
stage('Block 2 - Stage 1') {
steps {
echo "Block 2 - Stage 1"
build(job: "jenkins_job_3")
}
}
stage('Block 2 - Stage 2') {
steps {
echo "Block 2 - Stage 2"
build(job: "jenkins_job_4")
}
}
}
}
}
}
推荐答案
您不必将每个调用都放在一个阶段中的并行作业上,因此您可以这样操作:
You don't have to put each call to a parallel-job inside a stage, so you can do it as such:
pipeline {
agent any
stages {
stage('single run') {
parallel {
stage('Parallel Test 1') {
steps {
script {
def group1 = [:]
group1["test_1"] = {
echo "test_1"
sh(script: "date -u")
build(job: 'jenkins_job_1')
}
group1["test_2"] = {
echo "test_2"
sh(script: "date -u")
build(job: 'jenkins_job_2')
}
parallel group1
}
}
}
stage('Parallel Test 2') {
steps {
script {
def group2 = [:]
group2["test_3"] = {
echo "test_3"
sh(script: "date -u")
build(job: 'jenkins_job_3')
}
group2["test_4"] = {
echo "test_4"
sh(script: "date -u")
build(job: 'jenkins_job_4')
}
parallel group2
}
}
}
}
}
}
}
这篇关于如何使用多个并行块同时运行多个阶段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文