Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-49997

Pipeline Declarative post unsuccessful block

XMLWordPrintable

      In my declarative pipeline I need to repeat the same step in the unstable, failure, and aborted post conditions, e.g.

      post {
        always {
          // do some stuff to collect junit reports
        }
        success {
          // push the tags
        }
        unstable {
          sh "mvn nexus-staging:drop"
        }
        failure {
          sh "mvn nexus-staging:drop"
        }
        aborted {
          sh "mvn nexus-staging:drop"
        }
      }

      This is really crappy having to repeat the exact same tidy-up in three places.

      What I'd really like is something like:

      post {
        always {
          // do some stuff to collect junit reports
        }
        success {
          // push the tags
        }
        unsuccessful {
          sh "mvn nexus-staging:drop"
        }
      }

      Where the unsuccessful steps would run at the end. The sequence of execution would thus be:

      • always (first because it might affect the build result)
      • success (the result cannot get better, so none of the following blocks can turn the result to a success)
      • unstable (because we might have some steps that escalate the unstable to a failure, or get aborted because they take too long)
      • failure (once the result is failure, it cannot get better)
      • aborted (the failure block could be aborted)
      • unsuccessful (a catch-all for any of the previous error modes)

      With perhaps a finally condition at the end that always runs

            jtaboada Jose Blas Camacho Taboada
            stephenconnolly Stephen Connolly
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: