如何在声明式jenkins管道中编写presend脚本

问题描述 投票:0回答:1

我试图在电子邮件正文中发送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: "[email protected]"
            }


}

我收到如下错误

WorkflowScript: 30: expecting anything but ''\n''; got it anyway @ line 30, column 102.
   target/serenity-summary.html")
                                 ^

1 error

我需要将HTML文件附加到电子邮件正文本身,我需要在post部分中使用正确的presend脚本。

email jenkins groovy jenkins-pipeline declarative
1个回答
0
投票

我认为你错误地使用了管道步骤emailext。你可以尝试如下。

post {
  always {

    emailext(
        to: "[email protected]",
        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"

    )
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.