Send email on jenkins pipeline failure

前端 未结 6 1487
不知归路
不知归路 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:48

    At the moment you have to use this procedure with a try-catch to get a post-build action.

    But in the future this step is planned (actually it is in review). You can read the blog post for further information (see the declarative pipeline part). See also the the Jenkins Jira ticket and the pull request.

    Update:

    The Jenkins declarative pipeline now has the post section that will run steps conditionally at the end of each build. See the docs for more information.

    post {
     always {
       sh 'echo "This will always run"'
     }
     success {
      sh 'echo "This will run only if successful"'
     }
     failure {
      sh 'echo "This will run only if failed"'
     }
     unstable {
      sh 'echo "This will run only if the run was marked as unstable"'
     }
     changed {
      sh 'echo "This will run only if the state of the Pipeline has changed"'
      sh 'echo "For example, the Pipeline was previously failing but is now successful"'
      sh 'echo "... or the other way around :)"'
     }
    }
    

提交回复
热议问题