简体   繁体   English

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

[英]How to write presend script in declarative jenkins pipeline

I am trying to send HTML file in email body itself (not attachment). 我试图在电子邮件正文中发送HTML文件(不是附件)。 I have written Jenkins declarative pipeline as follows 我写了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"
            }


}

I am getting error as follows 我收到如下错误

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

1 error

I need to attach the HTML file to email body itself and I need proper presend script in post section. 我需要将HTML文件附加到电子邮件正文本身,我需要在post部分中使用正确的presend脚本。

I think you made a wrong usage of pipeline step emailext . 我认为你错误地使用了管道步骤emailext You can try as following. 你可以尝试如下。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM