我想在詹金斯的构建后操作后发送电子邮件。因此我编写了 jenkinsfile 如下。但我需要一些绝妙的脚本
1. zip 文件附件
2. 在附加文件之前,我需要将文件夹转换为zip格式。
注意:请不要建议电子邮件插件程序和配置。
我更喜欢 Jenkins 文件方法配置
pipeline {
agent any
stages {
stage('Testing') {
steps {
sh 'chmod +x mvnw'
sh './mvnw clean verify serenity:aggregate'
}
}
}
post {
failure {
script {
mail (to: '[email protected] /cdn-cgi/l/email-protection',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) failed",
body: "Please visit ${env.BUILD_URL} for further information"
);
}
}
success {
script {
mail (to: '[email protected] /cdn-cgi/l/email-protection',
subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) success.",
body: "Please visit ${env.BUILD_URL} for further information.",
);
}
}
}
}
您需要使用 jenkins zip 实用程序为该文件夹创建 zip 文件,然后使用 email ext 插件发送带有附件的电子邮件,请参见下面的示例:
pipeline {
agent any
stages {
stage('Testing') {
steps{
bat "del test.zip"
zip zipFile: 'test.zip', archive: false, dir: 'directory pattern as per your structure'
}
}
}
post {
failure {
emailext attachmentsPattern: 'test.zip', body: '''${SCRIPT, template="groovy-html.template"}''',
subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Failed",
mimeType: 'text/html',to: "email id"
}
success {
emailext attachmentsPattern: 'test.zip', body: '''${SCRIPT, template="groovy-html.template"}''',
subject: "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER} - Successful",
mimeType: 'text/html',to: "email id"
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)