title: Mark the build as unstable when a junit fails
body: <p>I deploy a maven project that has JUnit tests. When a test fail, the build is marked as <code>FAILED</code>. However, I want it to be marked as <code>UNSTABLE</code> when a test fails, and <code>FAILED</code> when there is a serious error .
  Here is my <code>Jenkinsfile</code>:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>node{
    stage ('Checkout')
    {
      checkout scm
    }
    stage ('Build')
    {
      try {
          sh '''
             mvn clean -B org.jacoco:jacoco-maven-plugin:prepare-agent install
          '''
          currentBuild.result = 'SUCCESS'
        } catch (Exception AssertionError) {
          currentBuild.result = 'UNSTABLE'
        } finally {
          step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
  
      }
    }
  }
  </code></pre>
  
  <p>But this is not working for me. I can't catch the <code>AssertionError</code> and the build is always marked as <code>FAILED</code>. Any ideas? Thank you.</p>