You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins Email Extension插件无法接收定制化邮件通知求助

Jenkins Email Extension 插件自定义邮件样式解决方案
  • 修正模板类型:你当前使用的groovy-text.template是纯文本模板,无法生成带样式的HTML邮件,这是核心问题。如果需要指定样式的HTML邮件,需使用HTML类型的模板,而非纯文本模板。
  • 配置邮件内容类型:在Jenkins系统配置的「Extended E-mail Notification」中,将Default Content Type设置为HTML (text/html),确保插件能正确解析HTML格式的内容。
  • 自定义HTML邮件内容:
    1. 进入「Manage Jenkins」→「Configure System」→「Extended E-mail Notification」,找到Default Content字段。
    2. 替换为自定义的HTML代码(可根据需求调整样式):
      <!DOCTYPE html>
      <html>
      <head>
          <style>
              .mail-container { width: 85%; margin: 20px auto; border: 1px solid #e0e0e0; border-radius: 6px; overflow: hidden; }
              .mail-header { background-color: #1a73e8; color: #fff; padding: 12px 18px; }
              .mail-content { padding: 18px; line-height: 1.7; }
              .build-status { font-size: 1.1em; font-weight: 600; color: #d93025; }
              .build-link { color: #1a73e8; text-decoration: none; }
          </style>
      </head>
      <body>
          <div class="mail-container">
              <div class="mail-header">
                  <h3>${PROJECT_NAME} 构建通知 #${BUILD_NUMBER}</h3>
              </div>
              <div class="mail-content">
                  <p>构建状态:<span class="build-status">${BUILD_STATUS}</span></p>
                  <p>构建详情:<a class="build-link" href="${BUILD_URL}">点击查看</a></p>
                  <p>触发时间:${BUILD_TIMESTAMP}</p>
              </div>
          </div>
      </body>
      </html>
      
  • 模板文件替代方案:若偏好使用模板文件,可在Jenkins的JENKINS_HOME/email-templates目录下创建自定义HTML模板文件(如custom-build-notify.template),将上述HTML代码写入文件,然后在邮件内容中引用:${SCRIPT, template="custom-build-notify.template"}
  • 验证配置:保存设置后手动触发一次构建,检查邮件样式是否符合预期。若仍有问题,排查模板中的HTML语法错误或变量是否正确引用。

内容的提问来源于stack exchange,提问作者rajus19

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 17:40:00