title: Jenkinsfile declarative syntax for conditional post-build step
body: <p>I have a Jenkinsfile for a multibranch pipeline like this:</p>
  
  <pre><code>pipeline {
      agent any
      stages {
          // ...
      }
      post { 
          failure { 
              mail to: 'team@example.com',
                   subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
                   body: "Something is wrong with ${env.BUILD_URL}"
          }
      }
  }
  </code></pre>
  
  <p>I want to only send email for failures on the master branch.  Is there a way to make the mail step conditional?  Based on the documentation a <code>when</code> directive may only be used inside a <code>stage</code>.</p>
  
  <ul>
  <li><a href="https://jenkins.io/doc/book/pipeline/syntax/#when" rel="noreferrer">https://jenkins.io/doc/book/pipeline/syntax/#when</a></li>
  <li><a href="https://jenkins.io/doc/pipeline/tour/post/" rel="noreferrer">https://jenkins.io/doc/pipeline/tour/post/</a></li>
  </ul>