How to use Jenkins declarative pipeline to build and test on multiple platforms
post{}
block should only followsteps{}
orparallel{}
(for parallel stages) to take effect.If you require post to be executed in a node environment, you should provide a node to the entire stage (
agent{}
statement).
You could try to use parallel stages execution. Also I'd suggest to use functions to shorten the code.
Something like this:
void Clean() { dir("build") { deleteDir() writeFile file:'dummy', text:'' // Creates the directory }}void SmthElse(def optionalParams) { // some actions here}pipeline { agent none options { skipDefaultCheckout(true) // to avoid force checkouts on every node in a first stage disableConcurrentBuilds() // to avoid concurrent builds on same nodes } stages { stage('Clean') { failfast false parallel { stage('Linux') { agent {label 'linux'} steps {Clean()} post { // post statements for 'linux' node SmthElse(someParameter) } } stage('Windows') { agent {label 'windows'} steps {Clean()} post { // post statements for 'windows' node } } stage('MacOS') { agent {label 'mac'} steps {Clean()} post { // post statements for 'mac' node } } } post { // Post statements OUTSIDE of nodes (i.e. send e-mail of a stage completion) } } // other stages (Build/Test/Etc.) }}
Alternatively you can use node
in post statements:
stage('Test') { steps { // your parallel Test steps } post { always { script { parallel ( "linux" : { node('linux') { // 'linux' node post steps } }, "windows" : { node('windows') { // 'windows' node post steps } } // etc ) } } }}