Parallel items in Jenkins Declarative pipeline

JoSSte

I am working on setting up automated build and deploy jobs in jenkins

Right now I have a single stage with parallel tasks set up like this

stage ('Testing & documenting'){
        steps {
            parallel (
                "PHPLOC" : {
                    echo "Running phploc"
                    sh "./src/vendor/phploc/phploc/phploc --exclude=./src/vendor --no-interaction --quiet --log-csv=./build/logs/loc.csv src tests"
                },
                "SLOC": {
                    echo "Running sloc"
                    sh "sloccount --duplicates --wide --details . > ./build/logs/sloccount.sc  2>/dev/null"
                },
                "CPD" : {
                    echo "Running copy-paste detection"
                    sh "./src/vendor/sebastian/phpcpd/phpcpd --fuzzy . --exclude src/vendor --log-pmd ./build/logs/phpcpd.xml || true"
                },
                "MD" : {
                    echo "Running mess detection on code"
                    sh "./src/vendor/phpmd/phpmd/src/bin/phpmd src xml phpmd_ruleset.xml --reportfile ./build/logs/phpmd_code.xml --exclude vendor,build --ignore-violations-on-exit --suffixes php"
                },
                "PHPUNIT" : {
                    echo "Running PHPUnit w/o code coverage"
                    sh "./src/vendor/phpunit/phpunit/phpunit --configuration phpunit-quick.xml" 
                }
            )
        }
    }

after reading https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/ I noticed that they use a different structure.

stage("Documenting and Testing") {
        parallel {
            stage("Documenting") {
                agent any
                stages {
                    stage("CPD") {
                        steps {
                            //CPD
                        }
                    }
                    stage("PMD") {
                        steps {
                            //PMD stuff
                        }
                    }
                }
                stage("Testing") {
                agent any
                stages {
                    stage("PHPUnit") {
                        steps {
                            //PHPUnit
                        }
                    }
                }
            }

I am not sure what the difference between these two approaches is

Dibakar Aditya

The first example running parallel inside the steps block was introduced by the earlier versions of the declarative pipeline. This had some shortcomings. For example, to run each parallel branch on a different agent, you need to use a node step, and if you do that, the output of the parallel branch won’t be available for post directives (at a stage or pipeline level). Basically the old parallel step required you to use Scripted Pipeline within a Declarative Pipeline.

The second example is a true declarative syntax introduced to overcome the shortcomings of the former. In addition, this particular example runs two serial stages within the parallel stage ‘Documenting’.

You can read this official blog to know more about the parallel directive https://jenkins.io/blog/2017/09/25/declarative-1/.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Jenkins parallel declarative pipeline

Jenkins Declarative Pipeline parallel stages

Parallel checkout in declarative Jenkins pipeline on multiple nodes

Dynamically defining parallel steps in declarative jenkins pipeline

Jenkins declarative pipeline parallel steps executors

Creating a sequential step in a jenkins declarative pipeline preceding a parallel stage

How to detect which parallel stage failed in a Jenkins declarative pipeline?

How to make parallel calls to the same function in stage in Jenkins Declarative Pipeline

Assigning variables in a parallel step using Declarative Pipeline steps in Jenkins

Parallel runs in declarative pipeline

Jenkins input on declarative pipeline

Jenkins scripted pipeline or declarative pipeline

Dynamic Variable in Jenkins Declarative Pipeline

Using waitForQualityGate in a Jenkins declarative pipeline

Jenkins: Using XmlSlurper In Declarative Pipeline

Jenkins dynamic declarative pipeline parameters

Jenkins Declarative Pipeline Docker Registry

Referencing variable in declarative jenkins pipeline

Not serializable error for jenkins declarative pipeline

Jenkins declarative pipeline @tmp folders

parallel steps on different nodes on declarative jenkins pipeline cannot access variables defined in global scope

Running non-matrix stages in parallel to a matrix in Jenkins declarative-pipeline

Jenkins Declarative Pipeline without Jenkins file in the repository

Parallel Example Jenkinsfile Declarative Pipeline Fails

Dynamic number of parallel steps in declarative pipeline

Jenkins pipeline (parallel && dynamically)?

Jenkins pipeline with parallel

Jenkins Pipeline With Parallel Command

Jenkins pipeline parallel not exeucting