摘要:本文主要向大家介绍了Linux运维知识之Jenkins pipeline 并行执行任务流,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。
本文主要向大家介绍了Linux运维知识之Jenkins pipeline 并行执行任务流,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。
我们在一个 stage 中设置多个子 stage 并行执行:
stages {
stage('Stage1') {
...
}
stage('并行执行的 Stage') {
parallel {
stage('Stage2.1') {
agent { label "test1" }
steps {
echo "在 agent test1 上执行的并行任务 1."
}
}
stage('Stage2.2') {
agent { label "test2" }
steps {
echo "在 agent test2 上执行的并行任务 2."
}
}
}
}
stage('Stage3') {
...
}
}
上面代码中任务的执行过程如下图所示:
任务 2.1 和任务 2.2 并行执行。
过去并行执行的任务都是单个的,但实际情况中我们还需要任务流级别的并行能力,如下图所示:
上图中显示有两条任务流在并行的执行,我们可以通过下面的代码来实现:
pipeline {
agent none
stages {
stage('Stage1') {
agent { label "master" }
steps {
timestamps {
echo '这是第一个被执行的 stage.'
sleep 5
}
}
}
stage("build, deploy and test on Windows and Linux") {
parallel {
stage("windows") {
agent {
label "master"
}
stages {
stage("build") {
steps {
timestamps {
echo "build on windows."
}
}
}
stage("deploy") {
steps {
timestamps {
echo "deploy on windows."
}
}
}
stage("test") {
steps {
timestamps {
echo "test on windows."
sleep 5
}
}
}
}
}
stage("linux") {
agent {
label "worker1"
}
stages {
stage("build") {
steps {
timestamps {
echo "build on linux."
}
}
}
stage("deploy") {
steps {
timestamps {
echo "deploy on linux."
}
}
}
stage("test") {
steps {
timestamps {
echo "test on linux."
sleep 5
}
}
}
}
}
}
}
stage('Stage3') {
agent { label "worker1" }
steps {
timestamps {
echo '这是最后一个被执行的 stage.'
}
}
}
}
}
为了显示任务的执行时间,笔者使用了 timestamper 插件。下图显示了笔者精简后的运行日志:
红框中的内容说明我们的两个任务流是完全并行执行的。这就是 1.3 版的声明式 pipeline 中增加的 “sequential stages” 功能。
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维Linux频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号