title: How to mark a build unstable in Jenkins when running shell scripts
body: <p>In a project I'm working on, we are using shell scripts to execute different tasks. Some are sh/bash scripts that run rsync, and some are PHP scripts. One of the PHP scripts is running some integration tests that output to JUnit XML, code coverage reports, and similar.</p>
  
  <p>Jenkins is able to <strong>mark the jobs as successful / failed based on <a href="http://en.wikipedia.org/wiki/Exit_status" rel="noreferrer">exit status</a></strong>. In <strong>PHP, the script exits with 1</strong> if it has detected that the tests failed during the run. The other shell scripts run commands and use the exit codes from those to mark a build as failed.</p>
  
  <pre><code>// :: End of PHP script:
  // If any tests have failed, fail the build
  if ($build_error) exit(1);
  </code></pre>
  
  <p>In <a href="https://wiki.jenkins-ci.org/display/JENKINS/Terminology" rel="noreferrer">Jenkins Terminology</a>, an unstable build is defined as:</p>
  
  <blockquote>
    <p>A build is unstable if it was built successfully and one or more publishers report it unstable. For example if the JUnit publisher is configured and a test fails then the build will be marked unstable.</p>
  </blockquote>
  
  <p>How can I get Jenkins to mark a build as unstable instead of only success / failed when running shell scripts?</p>