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

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

    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
            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
            Hide
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

            Show
            bitwiseman Liam Newman added a comment - Bulk closing resolved issues.

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: