标签: jenkins-email-ext

发送有关jenkins管道故障的电子邮件

如何在jenkins管道中添加一个旧式的后期构建任务,该任务在构建失败时发送电子邮件?我无法在GUI中找到管道的"后构建操作".我知道我可以包装整个构建脚本try/catch,但是当构建脚本很大时这看起来很难看,并且即使手动中止作业也会继续发送电子邮件.我想实现与email-ext基于previouse 的构建后操作相同的功能.

try {
    // Do sth
} catch(e) {
    emailext body: '$DEFAULT_CONTENT', 
        recipientProviders: [
            [$class: 'CulpritsRecipientProvider'],
            [$class: 'DevelopersRecipientProvider'],
            [$class: 'RequesterRecipientProvider']
        ], 
        replyTo: '$DEFAULT_REPLYTO', 
        subject: '$DEFAULT_SUBJECT',
        to: '$DEFAULT_RECIPIENTS'
    throw err
}
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-pipeline jenkins-email-ext

22
推荐指数
4
解决办法
5万
查看次数

如何在 Jenkins 声明性管道的发布阶段和 emailext 中访问 $GIT_COMMIT?

我想在构建成功/失败时发送电子邮件以及一些有用的 Git 信息,例如提交 SHA、先前成功的 SHA、提交消息等。我能够以旧的 UI 方式执行此操作,但现在我已经创建了声明性管道和现在我收到GIT_BRANCH is not supported in this context了收到的电子邮件。我正在使用 Jenkins 版本。2.89.3. 我的脚本:

pipeline {
    agent { 
        ...
    }
    stages {
        stage('Checkout') {
            steps {
                sh 'printenv'
                checkout scm: [$class: 'GitSCM', branches: [[[name: '*/development']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [url: 'https://github.com/myrepo/']]]
                sh 'git submodule foreach --recursive \'git submodule sync\''
                sh 'git submodule update --init --recursive'
            }
        }
        stage('Build') {
            steps {
               ...         
            }
        }
    }
    post {
        success {
            sh 'printenv'
            emailext body: …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-pipeline jenkins-email-ext

10
推荐指数
1
解决办法
2万
查看次数

Jenkins email-ext 插件 向群组发送电子邮件

有没有办法可以向通讯组列表发送电子邮件?这不起作用,因为只有个人电子邮件地址工作正常。我缺少任何设置吗?

jenkins jenkins-plugins jenkins-email-ext

6
推荐指数
1
解决办法
5390
查看次数

向 Jenkins 管道中的上游提交者发送通知电子邮件

由于 Jenkins 在我们推送到 GitHub 后自动构建所有项目,因此我们希望 Jenkins 在构建管道结束时发送电子邮件通知(无论构建是否成功)。

我使用以下脚本创建了一个共享库:

#!/usr/bin/env groovy

def call(String buildStatus = 'STARTED') {
    // build status of null means successful
    buildStatus = buildStatus ?: 'SUCCESS'

    // Default values
    def subject = "JENKINS-NOTIFICATION: ${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
    def details = """<p>${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
    <p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>"""

    // Send email to user who has started the build
    emailext(
        subject: subject,
        body: details,
        attachLog: true,
        compressLog: true,
        recipientProviders: [[$class: 'RequesterRecipientProvider'], [$class:'UpstreamComitterRecipientProvider']]
    )
}
Run Code Online (Sandbox Code Playgroud)

请注意,我定义了两个recipientProviders …

git continuous-integration jenkins email-ext jenkins-email-ext

5
推荐指数
1
解决办法
1万
查看次数

在果冻模板中访问自定义环境变量

使用 Jenkins 管道,您可以通过名为-env 的全局变量设置任何环境变量。

反过来,果冻模板使您能够访问 Jenkins API,包括hudson.model.AbstractBuildhudson.model.AbstractProject对象。

以下是我使用的片段:

詹金斯档案:

node { 
       env.MYVAR = 'My variable'
       emailext body: ${JELLY_SCRIPT, template="myTemplate"}, subject: 'MySubject', to: 'me'
}
Run Code Online (Sandbox Code Playgroud)

果冻模板(myTemplate):

<?jelly escape-by-default='true'?>
<!DOCTYPE html [
    <!ENTITY nbsp "&#38;#38;nbsp&#59;">
]>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define">
<head>
  <style>
      body table, td, th, p, h1, h2 {
      margin:0;
      font:normal normal 100% Georgia, Serif;
      background-color: #ffffff;
      }
  </style>
</head>
<body>
<j:set var="buildEnv" value="${build.getEnvironment(listener)}" />
<j:set var="myVar" value="${buildEnv.get('MYVAR')}" />
  <table>
    <tr>
      <td>Variable</td> …
Run Code Online (Sandbox Code Playgroud)

jelly jenkins jenkins-pipeline jenkins-email-ext

5
推荐指数
1
解决办法
1703
查看次数

在 Jenkins 管道的电子邮件正文中嵌入图像

我需要在电子邮件中添加一个图像作为电子邮件正文而不是附件,从 Jenkins 通过管道。我在 Jenkins 管道中使用 emailext 插件,下面是我正在使用的代码。

emailext (
          subject: "test email",
          body: """
          <html>
          <body>
          <p>please find attached score: Job '${env.JOB_NAME}':</p>
          <p> The last commit was by ${last_commit_user} </p>
          <p>Please check jenkins console at "</p> 
          <p> For detailed report on this analysis, visit "</p>
          </body>
          </html>
          """,
          to: email_recipients,
          attachmentsPattern: '${BUILD_NUMBER}.jpg'
)
Run Code Online (Sandbox Code Playgroud)

我不想使用作为附件的 "attachmentsPattern" ,我尝试使用,

body: """ 
<html>
<img src="image_name.jpg" >
</html>
"""
Run Code Online (Sandbox Code Playgroud)

这只是我电子邮件中的蓝色框,我提供了相对于我的 Jenkins 工作区的正确图像路径,我尝试搜索相关解决方案但徒劳无功。

html jenkins jenkins-plugins jenkins-pipeline jenkins-email-ext

5
推荐指数
1
解决办法
4710
查看次数

Jenkins 仅在最后 N 个构建失败时发送电子邮件通知(不是每次运行) - 可编辑的电子邮件通知

詹金斯 1.6 - 2.x

我有一个每分钟或每 2 分钟运行一次的工作,有时构建失败并且下一个构建通过。对于构建失败,我在 Jenkins 中使用了可编辑电子邮件通知插件。

使用此插件或任何其他插件/方式,我可以以某种方式配置 Jenkins 作业以仅在最近 3 个连续构建失败时向我发送失败构建通知吗?看着这些构建失败然后在下一次运行中成功并不有趣,所以我试图减少此类失败通知的频率或使其更智能。

我在这里提到了对新功能请求的评论:https : //wiki.jenkins.io/display/JENKINS/Email-ext+Template+Plugin?focusedCommentId=132940540# comment- 132940540但看看是否有人尝试过/取得了一些成就相似的。

notifications jenkins jenkins-plugins jenkins-email-ext

4
推荐指数
1
解决办法
6091
查看次数

如何从Jenkins声明脚本调用email-ext插件?

我正在编写一个简单的Jenkins声明性脚本来运行'make'并发送一封包含结果(成功/失败)的电子邮件.

我可以发送简单的电子邮件:

post {
    success {
        mail to:"myname@me.com", subject:"${currentBuild.fullDisplayName} - Failed!", body: "Success!"
    }
    failure {
        mail to:"myname@me.com", subject:"${currentBuild.fullDisplayName} - Failed!", body: "Failure!"
    }
}
Run Code Online (Sandbox Code Playgroud)

由此产生的电子邮件相当简单.

如何从脚本中调用email-ext插件来发送旧式的构建后电子邮件?(我想这应该使用email-ext的groovy-text.template).

我希望能够访问像CulpritsRecipientProvider这样的列表,并包含控制台日志的尾部.

jenkins jenkins-email-ext

3
推荐指数
1
解决办法
9899
查看次数

使用 Jenkins 管道访问电子邮件分机模板中的变量

我正在尝试使用 Jenkins 管道emailext附加模板文件。模板文件中的变量 (PROJNAME) 不可访问,我收到了异常电子邮件:

模板渲染期间引发的异常:没有这样的属性:类的环境:SimpleTemplateScript21 groovy.lang.MissingPropertyException:没有这样的属性:类的环境:SimpleTemplateScript21 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52) 在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) 在 SimplerunTemplate1(AbstractCallSite.java:307)。 1) 在 groovy.text.SimpleTemplateEngine$SimpleTemplate$1.writeTo(SimpleTemplateEngine.java:168) 在 groovy.text.SimpleTemplateEngine$SimpleTemplate$1.toString(SimpleTemplateEngine.java:180) 在 hudson.plugins.emailext.plugins.plugins. .renderTemplate(ScriptContent.java:151) 在 hudson.plugins。emailext.plugins.content.ScriptContent.evaluate(ScriptContent.java:82) at org.jenkinsci.plugins.tokenmacro.DataBoundTokenMacro.evaluate(DataBoundTokenMacro.java:208) at org.jenkinsci.plugins.tokenmacro.Parser.processToken(Parser. java:308) at org.jenkinsci.plugins.tokenmacro.Action$KiHW1UeqOdqAwZul.run(Unknown Source) at org.parboiled.matchers.ActionMatcher.match(ActionMatcher.java:96) at org.parboiled.parserunners.BasicParseRunner.match( BasicParseRunner.java:77) 在 org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)parboiled.matchers.ActionMatcher.match(ActionMatcher.java:96) 在 org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) 在 org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)parboiled.matchers.ActionMatcher.match(ActionMatcher.java:96) 在 org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77) 在 org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)

流水线脚本:

stage('Email') {
    def mailRecipients = "myemail@abc.com"
    def jobStatus = currentBuild.currentResult
    env.PROJNAME = 'project_name'
    echo "projname is ${PROJNAME}"
emailext body: '''${SCRIPT, template="test.template"}''',
    mimeType: 'text/html',
    subject: "[Jenkins] ${jobStatus}",
    to: "${mailRecipients}"
} …
Run Code Online (Sandbox Code Playgroud)

jenkins jenkins-plugins email-ext jenkins-pipeline jenkins-email-ext

2
推荐指数
1
解决办法
1万
查看次数