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

Last step of a multi-step always block fails if other steps in the stage failed

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • blueocean-plugin
    • Jenkins 2.332.3 / Blue Ocean 1.25.5

      Note: This is not the same as https://issues.jenkins-ci.org/browse/JENKINS-46551 because a single step in the post { always { } } block succeeds even if the earlier steps {} block throws an exception.

      The second "echo" statement in the post { always { } } section below fails with the exit code 127, which is the bash exit code from the earlier steps block attempt to run an arbitrary invalid shell command.

      Whereas, including only a single step in the post { always { } } works as expected.

      pipeline {
      agent {
        docker {
          image 'python'
        }
      }
        stages {
          stage('Run Tests') {
            steps {
              sh 'throwcommandnotfound'
            }
            post {
              always {
                echo 'this will succeed'
                echo 'this will fail'
              }
            }
          }
        }
      }
       

       For the second screenshot below, I removed the second "echo" statement.

          [JENKINS-51022] Last step of a multi-step always block fails if other steps in the stage failed

          Jeff Green created issue -
          Jeff Green made changes -
          Description Original: The second "echo" statement in the post \{ always \{ } } section below fails with the exit code 127, which is the bash exit code from the earlier steps block attempt to run an arbitrary invalid shell command.

          Whereas, including only a single step in the post \{ always \{ } } works as expected.
          {code:none}
          pipeline {
          agent {
            docker {
              image 'python'
            }
          }
            stages {
              stage('Run Tests') {
                steps {
                  sh 'throwcommandnotfound'
                }
                post {
                  always {
                    echo 'this will succeed'
                    echo 'this will fail'
                  }
                }
              }
            }
          }
           {code}
           
          New: This is almost definitely the declarative pipeline way to trigger https://issues.jenkins-ci.org/browse/JENKINS-46551 

          The second "echo" statement in the post \{ always \{ } } section below fails with the exit code 127, which is the bash exit code from the earlier steps block attempt to run an arbitrary invalid shell command.

          Whereas, including only a single step in the post \{ always \{ } } works as expected.
          {code:none}
          pipeline {
          agent {
            docker {
              image 'python'
            }
          }
            stages {
              stage('Run Tests') {
                steps {
                  sh 'throwcommandnotfound'
                }
                post {
                  always {
                    echo 'this will succeed'
                    echo 'this will fail'
                  }
                }
              }
            }
          }
           {code}
           
          Jeff Green made changes -
          Description Original: This is almost definitely the declarative pipeline way to trigger https://issues.jenkins-ci.org/browse/JENKINS-46551 

          The second "echo" statement in the post \{ always \{ } } section below fails with the exit code 127, which is the bash exit code from the earlier steps block attempt to run an arbitrary invalid shell command.

          Whereas, including only a single step in the post \{ always \{ } } works as expected.
          {code:none}
          pipeline {
          agent {
            docker {
              image 'python'
            }
          }
            stages {
              stage('Run Tests') {
                steps {
                  sh 'throwcommandnotfound'
                }
                post {
                  always {
                    echo 'this will succeed'
                    echo 'this will fail'
                  }
                }
              }
            }
          }
           {code}
           
          New: Note: This is not the same as https://issues.jenkins-ci.org/browse/JENKINS-46551 because a single step in the post \{ always \{ } } block succeeds even if the earlier steps \{} block throws an exception.

          The second "echo" statement in the post \{ always \{ } } section below fails with the exit code 127, which is the bash exit code from the earlier steps block attempt to run an arbitrary invalid shell command.

          Whereas, including only a single step in the post \{ always \{ } } works as expected.
          {code:none}
          pipeline {
          agent {
            docker {
              image 'python'
            }
          }
            stages {
              stage('Run Tests') {
                steps {
                  sh 'throwcommandnotfound'
                }
                post {
                  always {
                    echo 'this will succeed'
                    echo 'this will fail'
                  }
                }
              }
            }
          }
           {code}
           
          Jeff Green made changes -
          Jeff Green made changes -
          Description Original: Note: This is not the same as https://issues.jenkins-ci.org/browse/JENKINS-46551 because a single step in the post \{ always \{ } } block succeeds even if the earlier steps \{} block throws an exception.

          The second "echo" statement in the post \{ always \{ } } section below fails with the exit code 127, which is the bash exit code from the earlier steps block attempt to run an arbitrary invalid shell command.

          Whereas, including only a single step in the post \{ always \{ } } works as expected.
          {code:none}
          pipeline {
          agent {
            docker {
              image 'python'
            }
          }
            stages {
              stage('Run Tests') {
                steps {
                  sh 'throwcommandnotfound'
                }
                post {
                  always {
                    echo 'this will succeed'
                    echo 'this will fail'
                  }
                }
              }
            }
          }
           {code}
           
          New: Note: This is not the same as https://issues.jenkins-ci.org/browse/JENKINS-46551 because a single step in the post \{ always \{ } } block succeeds even if the earlier steps \{} block throws an exception.

          The second "echo" statement in the post \{ always \{ } } section below fails with the exit code 127, which is the bash exit code from the earlier steps block attempt to run an arbitrary invalid shell command.

          Whereas, including only a single step in the post \{ always \{ } } works as expected.
          {code:none}
          pipeline {
          agent {
            docker {
              image 'python'
            }
          }
            stages {
              stage('Run Tests') {
                steps {
                  sh 'throwcommandnotfound'
                }
                post {
                  always {
                    echo 'this will succeed'
                    echo 'this will fail'
                  }
                }
              }
            }
          }
           {code}
           For the second screenshot below, I removed the second "echo" statement.
          Victor Balakine made changes -
          Environment Original: Using Docker jenkinsci/blueocean New: Jenkins 2.332.3 / Blue Ocean 1.25.5
          Victor Balakine made changes -
          Component/s New: blueocean-plugin [ 21481 ]
          Component/s Original: core [ 15593 ]

            Unassigned Unassigned
            jeffgreenca Jeff Green
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: