How to use post steps with Jenkins pipeline on multiple agents?
I know this is old but I stumbled on this looking for something related. If you want to run the post step on any node, you can use
post {
always {
node(null) {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "[email protected]", sendToIndividuals: true])
}
}
}
https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#node-allocate-node Says that the label may be left blank. Many times in a declarative pipeline if something is left blank this results in an error. To work around this, setting it to null will often work.
wrap the step
that does the mailing in a node
step:
post {
always {
node('awesome_node_label') {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "[email protected]", sendToIndividuals: true])
}
}
}