Maxime Maxime - 1 month ago 19
Groovy Question

Jenkins Pipeline - how to get values after parallel execution

Is it possible to save some values during a parallel execution and use these values during a final step?

In the following example, I would like to know which jenkins slave is used during the parallel execution and use it during the final step.

node {
stage 'Checkout'
checkout([...])
stash includes: '**', name: 'binary'

stage 'Running simulation'
parallel (
"stream 1" : {
node {
unstash "binary"
sh "echo \"\$(whoami)@\$(hostname):\$PWD\""
// How to save the previous result

// Run simulation on node first slave
...
}
},
"stream 2" : {
node {
unstash "binary"
sh "echo \"\$(whoami)@\$(hostname):\$PWD\""
// How to save the previous result

// Run simulation on node second slave
...
}
}
)


stage 'Gathering results files'
// use the values of the slaves to retrieve some files.

stage 'Generate report'

}


Thanks for your answer.

Answer

My bad, I was using the 2.3 version of Pipeline Nodes and Processes Plugin. It works fine with the version 2.5

hostname = sh (returnStdout: true, script: 'hostname')
println hostname
Comments