I want to run the post part of my declarative pipeline inside a docker container. And I don't know how to set the agent only for post.
Sample of my pipeline
post {
always {
echo 'This will always run'
}
success {
mail ## my mail content;
}
}
And I want to run this mail command in a docker container.
agent. The agent section specifies where the entire Pipeline, or a specific stage, will execute in the Jenkins environment depending on where the agent section is placed. The section must be defined at the top-level inside the pipeline block, but stage-level usage is optional.
In declarative pipelines the agent directive is used for specifying which agent/slave the job/task is to be executed on. This directive only allows you to specify where the task is to be executed, which agent, slave, label or docker image.
Post Actions are just like other normal stages but that running in specific conditions. Jenkins supports 10 special action conditions which are running when these conditions meet. They are related to run status and can be defined in the post block both for the whole pipeline and per-stage.
Since the post section of a Pipeline is guaranteed to run at the end of a Pipeline's execution, we can add some notification or other steps to perform finalization, notification, or other end-of-Pipeline tasks. See Glossary - Build Status for the different build statuses: SUCCESS, UNSTABLE, and FAILED.
You can use the node(...){...}
block within the post steps, with or without the script {...}
block as applicable:
post {
always {
echo 'This will always run'
}
success {
node('docker') {
script {
mail ## my mail content;
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With