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

    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

            abayer Andrew Bayer added a comment -

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

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

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

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

            1.3.1 is releasing as we speak.

            abayer Andrew Bayer added a comment - 1.3.1 is releasing as we speak.

            abayer, according to doc we cannot use stages inside stage

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

            slavik334 Viachaslau Kabak added a comment - abayer , according to doc we cannot use stages inside stage https://jenkins.io/doc/book/pipeline/syntax/#stages
            bitwiseman Liam Newman added a comment -

            Bulk closing resolved issues.

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

            People

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

              Dates

                Created:
                Updated:
                Resolved: