title: How to catch manual UI cancel of job in Jenkinsfile
body: <p>I've tried to find documentation about how in a Jenkinsfile pipeline catching the error that occurs when a user cancels a job in jenkins web UI.</p>
  
  <p>I haven't got the <code>post</code>or <code>try/catch/finally</code> approaches to work, they only work when something fails within the build.</p>
  
  <p>This causes resources not to be free'd up when someone cancels a job.</p>
  
  <p>What I have today, is a script within a <strong>declarative pipeline</strong>, like so:</p>
  
  <pre><code>pipeline {
    stage("test") {
      steps {
        parallell (
          unit: {
            node("main-builder") {
              script {
                try { sh "&lt;build stuff&gt;" } catch (ex) { report } finally { cleanup }
              }
            }
          }
        )
      }
    }
  }
  </code></pre>
  
  <p>So, everything within <code>catch(ex)</code> and <code>finally</code> blocks is ignored when a job is manually cancelled from the UI.</p>