title: Jenkins pipeline - try catch for particular stage and subsequent conditional step
body: <p>I'm trying to replicate the equivalent of a conditional stage in Jenkins pipeline using a try / catch around a preceding stage, which then sets a success variable, which is used to trigger the conditional stage.</p>
  
  <p>It appears that a try catch block is the way to go, setting a success var to SUCCESS or FAILED, which is used as part of a when statement later (as part of the conditional stage).</p>
  
  <p>The code I am using is as follows:</p>
  
  <pre><code>pipeline {
      agent any
      stages {
          try{
              stage("Run unit tests"){
                  steps{
                      sh  '''
                          # Run unit tests without capturing stdout or logs, generates cobetura reports
                          cd ./python
                          nosetests3 --with-xcoverage --nocapture --with-xunit --nologcapture --cover-package=application
                          cd ..
                      '''
                      currentBuild.result = 'SUCCESS'
                  }
              }
          } catch(Exception e) {
              // Do something with the exception 
              currentBuild.result = 'SUCCESS'
          }
  
          stage ('Speak') {
              when {
                  expression { currentBuild.result == 'SUCCESS' }
              }
              steps{
                  echo "Hello, CONDITIONAL"
              }
          }
      }
  }
  </code></pre>
  
  <p>The latest syntax error I am receiving is as follows:</p>
  
  <pre><code>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
  failed:
  WorkflowScript: 4: Expected a stage @ line 4, column 9.
         try{
  </code></pre>
  
  <p>I've also tried lots of variations. </p>
  
  <p>Am I taking the wrong approach here? This seems like a fairly common requirement.</p>
  
  <p>Thanks.</p>