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

Stage B is not skipped due to failure in stage A's nested stage

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      After testing the new nested sequential stages feature in version 1.3 of pipeline-model-definition recently released, I found that the error handling is not working as (I) expected. Given this minimal Jenkinsfile

      pipeline {
          agent none
          stages {
              stage('A') {
                  stages {
                      stage('A.1') {
                          steps {
                              error('Error in stage A.1')
                          }
                      }
                  }
              }
              stage('B') {
                  steps {
                      echo('Executing stage B')
                  }
              }
          }
      }

      I expect that stage B is not executed, but it is, as the console output shows:

      Branch indexing
       > git rev-parse --is-inside-work-tree # timeout=10
      Setting origin to git@git:verification
       > git config remote.origin.url git@git:verification # timeout=10
      Fetching origin...
      Fetching upstream changes from origin
       > git --version # timeout=10
      using GIT_SSH to set credentials 
       > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
      Seen branch in repository origin/master
      Seen branch in repository origin/work/TEST-1234
      Seen 2 remote branches
      Obtained Jenkinsfile from fbd58047af16f0ab665ec6d550d21ceff1e91cfb
      Running in Durability level: MAX_SURVIVABILITY
      First time build. Skipping changelog.
      [Pipeline] stage
      [Pipeline] { (A)
      [Pipeline] stage
      [Pipeline] { (A.1)
      [Pipeline] error
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (B)
      [Pipeline] echo
      Executing stage B
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] End of Pipeline
      Finished: FAILURE

      Given a pipeline without nested stages the behaviour is as expected; stage B is skipped when stage A fails:

      pipeline {
          agent none
          stages {
              stage('A') {
                  steps {
                      error('Error in stage A')
                  }
              }
              stage('B') {
                  steps {
                      echo('Executing stage B')
                  }
              }
          }
      }

      Console output shows that stage B is skipped:

      Branch indexing
       > git rev-parse --is-inside-work-tree # timeout=10
      Setting origin to git@git:verification
       > git config remote.origin.url git@git:verification # timeout=10
      Fetching origin...
      Fetching upstream changes from origin
       > git --version # timeout=10
      using GIT_SSH to set credentials 
       > git fetch --tags --progress origin +refs/heads/*:refs/remotes/origin/*
      Seen branch in repository origin/master
      Seen branch in repository origin/work/TEST-1234
      Seen 2 remote branches
      Obtained Jenkinsfile from 203fe77650dbdd5392790cfe53558d7ef67fe0de
      Running in Durability level: MAX_SURVIVABILITY
      First time build. Skipping changelog.
      [Pipeline] stage
      [Pipeline] { (A)
      [Pipeline] error
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] stage
      [Pipeline] { (B)
      Stage "B" skipped due to earlier failure(s)
      [Pipeline] }
      [Pipeline] // stage
      [Pipeline] End of Pipeline
      ERROR: Error in stage A
      Finished: FAILURE

        Attachments

          Issue Links

            Activity

            Hide
            thxmasj Thomas Johansen added a comment -

            Andrew Bayer: Is this a bug or expected behaviour?

            Show
            thxmasj Thomas Johansen added a comment - Andrew Bayer : Is this a bug or expected behaviour?
            Hide
            abayer Andrew Bayer added a comment -

            It's a definite bug - I've reproduced it and am working on it now.

            Show
            abayer Andrew Bayer added a comment - It's a definite bug - I've reproduced it and am working on it now.
            Hide
            abayer Andrew Bayer added a comment -

            Yup, that was a goofy mistake on my part - I wasn't propagating errors from nested sequential stages at all. Sigh - sorry about that. PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/271, this'll be in 1.3.1. I'm going to wait til late next week before releasing 1.3.1, though, since I'm betting there are going to be other little bugs like this that come up. Thanks for reporting this!

            Show
            abayer Andrew Bayer added a comment - Yup, that was a goofy mistake on my part - I wasn't propagating errors from nested sequential stages at all. Sigh - sorry about that. PR up at https://github.com/jenkinsci/pipeline-model-definition-plugin/pull/271 , this'll be in 1.3.1. I'm going to wait til late next week before releasing 1.3.1, though, since I'm betting there are going to be other little bugs like this that come up. Thanks for reporting this!
            Hide
            thxmasj Thomas Johansen added a comment -

            Andrew Bayer: Would it be ok to release 1.3.1 now?

            Show
            thxmasj Thomas Johansen added a comment - Andrew Bayer : Would it be ok to release 1.3.1 now?
            Hide
            abayer Andrew Bayer added a comment -

            Sorry, I got distracted - once JENKINS-52084 is ready, yes, I'll release 1.3.1

            Show
            abayer Andrew Bayer added a comment - Sorry, I got distracted - once JENKINS-52084 is ready, yes, I'll release 1.3.1
            Hide
            thxmasj Thomas Johansen added a comment -

            Andrew Bayer: Perfect. I see the PR for JENKINS-52084 was approved.

            Show
            thxmasj Thomas Johansen added a comment - Andrew Bayer : Perfect. I see the PR for JENKINS-52084 was approved.
            Hide
            abayer Andrew Bayer added a comment -

            1.3.1 is releasing as we speak.

            Show
            abayer Andrew Bayer added a comment - 1.3.1 is releasing as we speak.
            Hide
            slavik334 Viachaslau Kabak added a comment -

            Andrew Bayer, according to doc we cannot use stages inside stage

            https://jenkins.io/doc/book/pipeline/syntax/#stages

            Show
            slavik334 Viachaslau Kabak added a comment - Andrew Bayer , according to doc we cannot use stages inside stage https://jenkins.io/doc/book/pipeline/syntax/#stages

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                thxmasj Thomas Johansen
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: