Send email on jenkins pipeline failure

前端 未结 6 1486
不知归路
不知归路 2021-01-30 17:16

How can i add to a jenkins pipeline an old-style post-build task which sends email when the build fails? I cannot find \"Post-build actions\" in the GUI for a pipeline. I know t

6条回答
  •  一生所求
    2021-01-30 17:40

    to DRY your scripted pipelines you can easily extend Jenkins with your own shared library and define a custom step emailOnError like

    def call(Closure action) {
        try {
            action()
        } catch(e){
            emailext    body: '$DEFAULT_CONTENT', 
                        recipientProviders: [
                            [$class: 'DevelopersRecipientProvider'],
                            [$class: 'RequesterRecipientProvider']
                        ], 
                        replyTo: '$DEFAULT_REPLYTO', 
                        subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - ERROR!',
                        to: '$DEFAULT_RECIPIENTS'
            throw err
        }   
    }
    

    then use it like

    emailOnError() {
        // Do sth   
    }
    

提交回复
热议问题