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

Permit "Execute shell" jobs to return 2 for "unstable"

    XMLWordPrintable

Details

    Description

      Currently, users of "Execute shell" builds must fetch the jenkins-cli jar and execute it in order to mark a build as unstable. For example:

      set -e
      wget ${JENKINS_URL}jnlpJars/jenkins-cli.jar
      make
      if ! make check; then 
        java -jar jenkins-cli.jar set-build-result unstable && exit 0
        exit 1
      fi
      

      will flag as unstable and exit.

      That works, but it's a right pain. The alternative is text-finder plugin string matching, which is arguably worse.

      What'd be ideal is to let the return code 2 mean "unstable" to Jenkins. So one could just replace the above with:

      set -e
      make
      make check || exit 2
      

      I'll see what's involved in adding this, but wanted to put the idea out.

      Attachments

        Issue Links

          Activity

            Huh, found that it configurable, hope it disabled by default.

            integer Kanstantsin Shautsou added a comment - Huh, found that it configurable, hope it disabled by default.
            jbochenski Jakub Bochenski added a comment - - edited

            oleg_nenashev danielbeck ringerc can you take a look at JENKINS-47606? I run into problems when trying to use this in a Maven project

            jbochenski Jakub Bochenski added a comment - - edited oleg_nenashev danielbeck ringerc can you take a look at  JENKINS-47606 ? I run into problems when trying to use this in a Maven project
            fatcash Alexej Ismailov added a comment - - edited

            I'm sorry if this is a stupid question, but how do I use this? How to configure jenkins to interpret exit code 2 as unstable?
            If I do this inside a step: 

            sh """exit 2"""

            I get same behaviour as if I would exit with 1:

            11:27:13 Catching error for later recovery: hudson.AbortException: script returned exit code 2
            ...
            [Pipeline] End of PipelineERROR: script returned exit code 2
            Finished: FAILURE
            
            fatcash Alexej Ismailov added a comment - - edited I'm sorry if this is a stupid question, but how do I use this? How to configure jenkins to interpret exit code 2 as unstable? If I do this inside a step:  sh """exit 2""" I get same behaviour as if I would exit with 1: 11:27:13 Catching error for later recovery: hudson.AbortException: script returned exit code 2 ... [Pipeline] End of PipelineERROR: script returned exit code 2 Finished: FAILURE

            fatcash all of the above examples, being from 2016, were probably using the "classic" interface which has a field in the UI. In pipeline code, you want to use the "returnStatus" flag when calling sh - see https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script - unfortunately you cannot use "returnStdout" at the same time; see JENKINS-44930.

            aarondmarasco_vsi Aaron D. Marasco added a comment - fatcash all of the above examples, being from 2016, were probably using the "classic" interface which has a field in the UI. In pipeline code, you want to use the "returnStatus" flag when calling sh - see https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script - unfortunately you cannot use "returnStdout" at the same time; see JENKINS-44930 .
            rvernica Rares Vernica added a comment -

            See this screenshot on how you can set it. Notice the Exit code to set build unstable field.

            rvernica Rares Vernica added a comment - See this screenshot on how you can set it. Notice the Exit code to set build unstable field.

            People

              Unassigned Unassigned
              ringerc Craig Ringer
              Votes:
              11 Vote for this issue
              Watchers:
              18 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: