Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm building a pipeline using scripted pipeline and as I can see from
https://jenkins.io/doc/pipeline/tour/post/
, for declarative pipeline, we can use post actions.
Similarly I tried in declarative pipeline -
node {
stage("Stage 1") {
script {
FAILED_STAGE=env.STAGE_NAME
echo "stage 1"
stage("Stage 2") {
script {
FAILED_STAGE=env.STAGE_NAME
echo "stage 2"
error "failed for some reason."
stage("Stage 3") {
script {
FAILED_STAGE=env.STAGE_NAME
echo "stage 3"
post {
failure {
echo "Failed stage name: ${FAILED_STAGE}"
But I do not see failure block of post executed even if pipeline failed. Can you please help to understand if it has some different syntax for scripted pipeline?
You are using a scripted pipeline
and not a declarative pipeline
(see the difference here). The syntax is completely different so you can't use a post-stage
(existing for declarative pipeline) in a scripted pipeline
(like your pipeline).
You have two options here.
You convert your scripted pipeline
to a declarative pipeline
(see syntax here) and simply use the post-stage
like you have it used in your questoin. (I would prefer this option)
Implement the post-stage
for your scripted pipeline
by yourself in a finally-block
(see this SO question for help)
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.