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

Error during always block skips execution of remaining steps

      Here's a trivial example of a general problem:

      pipeline {
          agent any
          stages {
              stage ("Example") {
                  steps {
                      // Install dependencies
                      sh 'npm install'
                      echo 'Execute build that creates artifacts'
                      echo 'Execute step that fails to create the expected junit test file'
                  }
              }
          }
          post {
              always {
                  junit 'reports/**'
                  echo 'This step and everything after it won't run.'
                  archive '**'
                  echo "send email to people with final build status"
              }
          }
      }
      

      I have an always block, but I can't actually guarantee that all steps in that always block will all always attempt to run.

      In Scripted Pipeline I could wrap each of these in a try-catch, but I can't do that in Declarative.

      I can reorder these steps to put the ones that I know won't fail earlier, but what about the email step? I want that to be last, so it gets the proper build status in the email.

      abayer suggested a catchError block. But depending on which step fails, that doesn't get the right behavior either. I want each step in the always to run exactly once no matter the build status. If the second step fails the catchError can't tell which one failed and not to run the first step again.

      Logically what I would expect to work:

      pipeline {
          agent any
          stages {
              stage ("Example") {
                  steps {
                      // Install dependencies
                      sh 'npm install'
                      echo 'Execute build that creates artifacts'
                      echo 'Execute step that fails to create the expected junit test file'
                  }
              }
          }
          post {
              always {
                  junit 'reports/**'
              }
              always {
                  echo 'This step and everything after it won't run.'
              }
              always {
                  archive '**
              }
              always {
                  echo "send email to people with final build status"
              }
          }
      }
      

      However, I'm not allowed to have more than one always block.

          [JENKINS-41239] Error during always block skips execution of remaining steps

          Liam Newman created issue -
          Liam Newman made changes -
          Attachment New: Screen Shot 2017-01-25 at 12.32.41 PM.png [ 35617 ]
          James Dumay made changes -
          Summary Original: Declarative: error during always block skips execution of remaining steps New: Error during always block skips execution of remaining steps
          James Dumay made changes -
          Epic Link New: JENKINS-45427 [ 183595 ]
          CloudBees Inc. made changes -
          Remote Link New: This issue links to "CloudBees Internal CD-19 (Web Link)" [ 19136 ]
          James Dumay made changes -
          Sprint New: Pipeline - Candidates [ 381 ]
          Vivek Pandey made changes -
          Sprint Original: Pipeline - Candidates [ 381 ]
          Vivek Pandey made changes -
          Rank New: Ranked higher
          Andrew Bayer made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Andrew Bayer made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]
          Andrew Bayer made changes -
          Remote Link New: This issue links to "PR #258 (Web Link)" [ 20366 ]

            abayer Andrew Bayer
            bitwiseman Liam Newman
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: