如何在声明性詹金斯管道中编写presend脚本

时间:2019-04-25 12:16:26

标签: email jenkins groovy jenkins-pipeline declarative

我正在尝试通过电子邮件正文本身(而非附件)发送HTML文件。我写了如下的詹金斯声明式管道

<head>
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick.css" />
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.css" />
</head>

<div class="user_opinions" style="position: relative; outline: 0; width: 100% !important;">
  <div style="">
    <img src="/g/p/user_1.png" width="100%" alt="">
    <div style=" margin: 10px;">
      <p style="">Es sind definitiv die Filter die es einfach machen. Ich kann genau die bla finden nach der ich gesucht habe.</p>
      <div style="border-top: 1px solid #ccc; width: 100px;margin-bottom:10px;"></div>
      <strong>Jens K</strong>
    </div>
  </div>
  <div>
    <img src="/g/p/user2.jpg" width="100%" alt="">
    <div style=" margin: 10px;">
      <p>Es sind definitiv die Filter auf x die es einfach machen. Ich kann genau die blub finden nach der ich gesucht habe.</p>
      <div style="border-top: 1px solid #ccc; width: 100px;margin-bottom:10px;"></div>
      <strong>Jens K</strong>
    </div>
  </div>
   <div>
    <img src="/g/p/user2.jpg" width="100%" alt="">
    <div style=" margin: 10px;">
      <p>Es sind definitiv die Filter auf x die es einfach machen. Ich kann genau die blub finden nach der ich gesucht habe.</p>
      <div style="border-top: 1px solid #ccc; width: 100px;margin-bottom:10px;"></div>
      <strong>Jens K</strong>
    </div>
  </div>
   <div>
    <img src="/g/p/user2.jpg" width="100%" alt="">
    <div style=" margin: 10px;">
      <p>Es sind definitiv die Filter auf x die es einfach machen. Ich kann genau die blub finden nach der ich gesucht habe.</p>
      <div style="border-top: 1px solid #ccc; width: 100px;margin-bottom:10px;"></div>
      <strong>Jens K</strong>
    </div>
  </div>
   <div>
    <img src="/g/p/user2.jpg" width="100%" alt="">
    <div style=" margin: 10px;">
      <p>Es sind definitiv die Filter auf x die es einfach machen. Ich kann genau die blub finden nach der ich gesucht habe.</p>
      <div style="border-top: 1px solid #ccc; width: 100px;margin-bottom:10px;"></div>
      <strong>Jens K</strong>
    </div>
  </div>
</div>

<footer>
  <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.min.js"></script>
</footer>

我得到如下错误

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"
            }


}

我需要将HTML文件附加到电子邮件正文本身,并且在帖子部分需要适当的presend脚本。

1 个答案:

答案 0 :(得分:0)

我认为您错误地使用了流水线步骤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"

    )
  }
}
相关问题