![](/img/trans.png)
[英]How to send “back to normal” notifications in Jenkins Declarative Pipeline?
[英]How to write presend script in declarative jenkins pipeline
我試圖在電子郵件正文中發送HTML文件(不是附件)。 我寫了Jenkins聲明性管道如下
post {
always {
presendScript: "def reportPath=build.getWorkspace().child("target/serenity-summary.html")
msg.setContents(reportPath.readToString(), "text/html")"
emailext attachmentsPattern: "Serenity_Test_Results${env.BUILD_NUMBER}.zip" ,
body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} More info at: ${env.BUILD_URL}Unzip the attached document and click on index.html to view complete test results",
subject: "API Testing: Jenkins Job Results - Build # ${env.BUILD_NUMBER} - Failed",
mimeType: 'text/html',to: "xyz@abc.com"
}
}
我收到如下錯誤
WorkflowScript: 30: expecting anything but ''\n''; got it anyway @ line 30, column 102.
target/serenity-summary.html")
^
1 error
我需要將HTML文件附加到電子郵件正文本身,我需要在post部分中使用正確的presend腳本。
我認為你錯誤地使用了管道步驟emailext
。 你可以嘗試如下。
post {
always {
emailext(
to: "xyz@abc.com",
mimeType: 'text/html',
attachmentsPattern: "Serenity_Test_Results${env.BUILD_NUMBER}.zip",
subject: "API Testing: Jenkins Job Results - Build # ${env.BUILD_NUMBER} - Failed",
presendScript: 'def reportPath=build.getWorkspace().child("target/serenity-summary.html");msg.setContents(reportPath.readToString(), "text/html")',
body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} " +
"More info at: ${env.BUILD_URL}Unzip the attached document and click on index.html to view complete test results"
)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.