jeudi 29 mars 2018

Jenkins declarative pipeline. Conditional statement in post block

Have a Jenkins pipeline. Need/want to send emails when build succeeds. Email about all branches to maillist-1 and filter builds of master branch to maillist-master.
I tried using if and when statements-steps but both of them fail in post block.

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'
        )
      }
    }

}

How wanted behavior could be achieved?

Aucun commentaire:

Enregistrer un commentaire