When using the Jenkins pipeline where each stage runs on a different agent, it is good practice to use agent none
at the beginning:
pipeline {
agent none
stages {
stage('Checkout') {
agent { label 'master' }
steps { script { currentBuild.result = 'SUCCESS' } }
}
stage('Build') {
agent { label 'someagent' }
steps { bat "exit 1" }
}
}
post {
always {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: "[email protected]", sendToIndividuals: true])
}
}
}
But doing this leads to Required context class hudson.FilePath is missing
error message when the email should go out:
[Pipeline] { (Declarative: Post Actions)
[Pipeline] step
Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
[Pipeline] error
[Pipeline] }
When I change from agent none
to agent any
, it works fine.
How can I get the post
step to work without using agent any
?
node('master')
and now it works. Thank you. If I omit the label, I get the errorWorkflowScript: 15: Missing required parameter: "label"
. Can you adjust your answer? – Footle