概要
Jobエラーをメール通知する方法を調べたのでメモしておく。
ファイル構成
ファイル構成
├ script
│ └ mail.groovy
└ Jenkinsfile
通知メソッド作成
外部ファイルに分離してメソッドを定義します。
script/mail.groovy
/**
* メール通知
*
*/
// メールをGmailに送信する
def send(result) {
mail to: "hoge@example.com",
subject: "${env.JOB_NAME} #${env.BUILD_NUMBER} [${result}]",
body: "Build URL: ${env.BUILD_URL}.\n\n"
}
return this
Jenkinsfile作成
テストシナリオを作成する。
Jenkinsfile
# !/usr/bin/env groovy
pipeline {
agent any
stages {
stage('fail') {
error('Fail')
}
}
post {
failure {
mail = load "${pwd()}/script/mail.groovy"
mail.send(currentBuild.currentResult)
}
}
}