title: Jenkins declarative pipeline. Conditional statement in post block
body: <p>Have a Jenkins pipeline. Need/want to send emails when build succeeds. Email about all branches to <em>maillist-1</em> and filter builds of master branch to <em>maillist-master</em>.<br>
  I tried using <code>if</code> and <code>when</code> statements-steps but both of them fail in post block.</p>
  
  <pre><code>pipeline {
    agent ...
    stages {...}
    post{
      success{
        archiveArtifacts: ...
        if( env.BRANCH_NAME == 'master' ){
          emailext( to: 'maillist-master@domain.com'
                  , replyTo: 'maillist-master@domain.com'
                  , subject: 'Jenkins. Build succeeded :^) '
                  , body: params.EmailBody
                  , attachmentsPattern: '**/App*.tar.gz'
          )
        }
        emailext( to: 'maillist-1@domain.com'
                  , replyTo: 'maillist-1@domain.com'
                  , subject: 'Jenkins. Build succeeded :^) '
                  , body: params.EmailBody
                  , attachmentsPattern: '**/App*.tar.gz'
          )
        }
      }
  
  }
  </code></pre>
  
  <p>How wanted behavior could be achieved?</p>