Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkins (declarative) pipeline post action 'success' before 'always'?

Is it possible to do "success" post build before "always" ?

For exemple, if I do that :

post {
    success{
        archiveArtifacts artifacts: 'server/target/*.jar'
        deleteDir ()
    }
    always{
        deleteDir()
    }

}

In console Output it's done upside down...

" [Pipeline] deleteDir

[Pipeline] archiveArtifacts Archiving artifacts "

To bypass that, I use :

success{
        archiveArtifacts artifacts: 'server/target/*.jar'
        deleteDir ()
    }
    failure{
        deleteDir()
    }
    aborted{
        deleteDir()
    }
}
like image 600
flopic Avatar asked Sep 27 '17 13:09

flopic


People also ask

What are three important stages in Jenkins pipeline?

Stage. A stage block defines a conceptually distinct subset of tasks performed through the entire Pipeline (e.g. "Build", "Test" and "Deploy" stages), which is used by many plugins to visualize or present Jenkins Pipeline status/progress.

Which of these is the correct sequence of stages used in a Jenkins pipeline?

It contains a group of states called build, deploy, test and release. These events are interlinked with each other. Every state has its events, which work in a sequence called a continuous delivery pipeline.

Which is better scripted or declarative pipeline?

Basically, declarative and scripted pipelines differ in terms of the programmatic approach. One uses a declarative programming model and the second uses an imperative programming mode. Declarative pipelines break down stages into multiple steps, while in scripted pipelines there is no need for this.

What is the importance of post section in the Jenkins pipeline?

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.


2 Answers

You can use cleanup stage.

Example: https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/83abd0ec35960c1f2a37b6a66b2d26385b2962e2/pipeline-model-definition/src/test/resources/postChecksAllConditions.groovy

PR: https://github.com/jenkinsci/pipeline-model-definition-plugin/commit/83abd0ec35960c1f2a37b6a66b2d26385b2962e2#diff-136d8ce8670181449534f5b993a87051

like image 89
suresh Avatar answered Sep 20 '22 15:09

suresh


No, you cannot change this order. The steps alway run in order: always, changed, success, unstable, failure

https://www.cloudbees.com/sites/default/files/declarative-pipeline-refcard.pdf

like image 24
Rob Hales Avatar answered Sep 22 '22 15:09

Rob Hales