【问题标题】:Include html file in body email with email-ext plugin in jenkins pipeline在 jenkins 管道中使用 email-ext 插件在正文电子邮件中包含 html 文件
【发布时间】:2016-11-15 17:32:23
【问题描述】:

我需要在 jenkins 管道中使用 email-ext 插件包含来自 html 文件的电子邮件内容(我的 jenkins 是 2.24 版本),我试试这个

emailext (
  subject: "some subject",
  body: "${FILE,path="enteryPath/template.html"}",
  to: "email@example.com"
)  

但不适合我:(有什么建议或解决方案吗??谢谢提前。

【问题讨论】:

标签: jenkins jenkins-pipeline email-ext


【解决方案1】:

您可以使用attachmentsPattern 参数。

emailext (
  subject: "some subject",
  body: "${FILE,path="enteryPath/template.html"}",
  to: "email@example.com"
  attachmentsPattern: 'enteryPath/template.html'
)  

【讨论】:

  • 在我的 html 文件中放在哪里?
  • @vijay 你可以把它放在 Jenkins 有读取权限的任何地方。
  • @VitaliiVitrenko,假设 template.html 上有一个 标签? 我们将如何定义它?在这里使用图像 sn-p 对我不起作用。有什么想法吗?
  • @PANDAMAN 我相信您应该为图像使用某种托管,而不是将其存储在 Jenkins 机器上。但这确实超出了这个问题的范围。请创建另一个或搜索现有的。
【解决方案2】:

你不能将身体存储在工作区中吗?然后运行:

emailext (
  subject: "some subject",
  body: readFileFromWS("enteryPath/template.html"),
  to: "email@example.com"
) 

但这意味着正文在创建和转发时是静态的,猜你希望在发送邮件时读取它?

【讨论】:

    【解决方案3】:
        stage ('email'){
        steps{
          script{
                 echo "hello"
                 emailext (subject: "some subject", body: '${FILE,path="template.html"}',to: "xyz@gmail.com")  
    
                }
            }       
      }
    

    为 Jenkins 安装 email-ext 插件,您可以将上述代码作为阶段的一部分发送电子邮件,并且此处的 path 将相对于 Jenkins 工作区。

    【讨论】:

      【解决方案4】:

      你可以利用 readFile()

      emailext (
                  mimeType: 'text/html',
                  to: "sample@email.com",
                  attachLog: true,
                  subject: 'Subject Line',
                  body: readFile("path/to/html/file")
              )
      

      readFile 会将其读取为字符串流并将其交给 emailext 插件,因此如果您可能使用了任何特殊变量,例如

      ${BUILD_NUMBER}

      ${BUILD_LOG_REGEX}

      将被正确编译并替换为解释值。

      【讨论】:

        猜你喜欢
        • 2014-03-30
        • 1970-01-01
        • 1970-01-01
        • 2016-08-14
        • 1970-01-01
        • 2016-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多