Reputation: 3372
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
Upvotes: 0
Views: 619
Reputation: 4203
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/.
Upvotes: 1