Jenkins pipeline parallel execution of task flow

Source: Internet
Author: User

The author describes how to perform parallel tasks in declarative pipeline in the article "Jenkins performs tasks in parallel in declarative pipeline." A while ago, Jenkins released the 1.3 version of the declarative pipeline (declarative pipeline), which continues to enhance the ability to perform tasks in parallel: a task that executes in parallel can be a task flow. The official call this function "sequential stages", this article will explain "sequential stages", and demonstrate its usage through demo.

previous tasks in parallel mode

As described in the article "Jenkins performs tasks in parallel in declarative pipeline", we set up multiple sub-stages in a stage in parallel execution:

Stages {Stage ('Stage1') {        ...    } Stage ('Stage for parallel execution') {parallel {stage ('Stage2.1') {agent {label"test1"} steps {Echo "Parallel Task 1 performed on agent Test1."}} stage ('Stage2.2') {agent {label"test2"} steps {Echo "Parallel Task 2 performed on Agent Test2."}}}} stage ('Stage3') {        ...    }}

The tasks in the code above are executed as shown in the following procedure:

Task 2.1 and Task 2.2 are executed in parallel.

executing task flows in parallel

The tasks that were performed in parallel in the past are single, but in reality we also need the parallel capabilities of the task flow level, as shown in:

Shows that there are two task streams in parallel execution, which we can do with the following code:

Pipeline {Agent None Stages {stage ('Stage1') {agent {label"Master"} steps {timestamps {Echo 'This is the first stage to be executed.'                    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 ( /c7>"Deploy") {steps {timestamps { Echo "deploy on Windows."}} } stage ( /c4>"Test") {steps {timestamps { Echo "test on Windows."                                    Sleep 5                                }                            }                        }                    } } stage ("Linux") {agent {label"Worker1"} stages {Stage ("Build") {steps {timestamps { Echo "build on Linux."}} } stage ( /c5>"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 'This is the last stage to be executed.'                }            }        }    }}

In order to show the execution time of the task, I used the Timestamper plugin. Shows the author's streamlined run log:

The contents of the red box show that our two task streams are executed in full parallel. This is the "sequential stages" feature added in the 1.3 version of declarative pipeline.

Summary

Today, Jenkins is very supportive of the execution of parallel tasks in declarative pipeline (though it has undergone a slightly lengthy process). At the beginning of 2017, the author found that the declarative pipeline could not support parallel tasks, and later began to support relatively elementary parallel tasks, which was introduced in the article "Jenkins in parallel in declarative pipeline". By this year (2018) July declarative pipeline released version 1.3, which began to support the task flow level parallelism described in this article. At this point, the author thinks that the parallel execution function of the task in Jenkins declarative pipeline is quite perfect.

Reference:
Sequential Stages (new feature of declarative pipeline 1.3)

Jenkins pipeline parallel execution of task flow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.