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

Declarative Pipeline: set the build result when tests fail without a script block

XMLWordPrintable

      pipeline {
      
          agent any
      
          stages {
              stage ('Build & Test') {
                  steps {
                      sh 'echo Building... Failure here will fail the build'
                      script {
                          try {
                              echo 'Running tests...'
                              sh 'exit 1'
                          }
                          catch (exc) {
                              echo 'Testing failed!'
                              currentBuild.result = 'UNSTABLE'
                          }
                      }
                  }
              }
          }
      }
      

      E.g. as described here https://lastviking.eu/how_to_set_result_as_unstable_from_declarative_pipeline.html

      It would be nice to have a way to set result to unstable without having to use `script` or a framework specific publisher plugin (e.g. junit plugin)

            abayer Andrew Bayer
            jbochenski Jakub Bochenski
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: