简体   繁体   English

jenkins下游作业如何通过email-ext向上游git提交者发送电子邮件通知

[英]how can jenkins downstream job send email notification to upstream git committers via email-ext

this question is about how to send emails to git committers who broke integration tests in a downstream job, in jenkins, and see the list of changes in the downstream job. 这个问题是关于如何发送电子邮件给git提交者,这些提交者在jenkins的下游作业中破坏了集成测试,并查看下游作业中的更改列表。

i haven't tried everything i wrote here, so i could be wrong, these are impressions from the code i encountered. 我没有尝试过我在这里写的所有东西,所以我可能是错的,这些是我遇到的代码的印象。

there are apparently many attempts to answer this question, but none appear satisfactory, so i will elaborate. 显然有很多尝试回答这个问题,但没有一个看起来令人满意,所以我会详细说明。 details follow: 细节如下:

we used to work with svn. 我们曾经和svn合作过。 our job hierarchy was one job checks out and compiles, and triggers other jobs that take the compilation artifacts and execute misc integration tests on them. 我们的作业层次结构是一个作业检出并编译,并触发其他作业,这些作业采用编译工件并对它们执行misc集成测试。

emails need to be sent to the upstream svn committers who broke the build. 需要将电子邮件发送给破坏构建的上游svn提交者。

we like to send emails via email-ext plugin (https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin) because it is very customizable, and we use this functionality heavily. 我们喜欢通过email-ext插件(​​https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin)发送电子邮件,因为它非常可定制,我们大量使用此功能。

email ext plugin uses the changelog.xml of the current job to discover who broke the build. email ext plugin使用当前作业的changelog.xml来发现谁破坏了构建。 since the changelog.xml is created by the checkout operation, it exists in the upstream job. 由于changelog.xml是由checkout操作创建的,因此它存在于上游作业中。 therefore, email-ext doesn't seem to know whom it should email. 因此,email-ext似乎不知道应该通过电子邮件发送给谁。

IF you decide to include culprits, you can start your jenkins with -Dhudson.upstreamCulprits=true, which changes the behavior of email-ext, but that will not help you if you don't want to include culprits. 如果您决定包含罪犯,您可以使用-Dhudson.upstreamCulprits = true启动您的jenkins,这会更改email-ext的行为,但如果您不想包含罪犯,这对您没有帮助。 additionally, the changeset doesn't seem to be available in the downstream job. 此外,变更集似乎在下游作业中不可用。

there is also a blame-upstream committers plugin, but it doesn't seem to play well with email-ext. 还有一个责备上游提交者插件,但它似乎不适用于email-ext。

upstreamCulprits and blame-upstream both seem to need fingerprinting, and we'd rather not because we have a LOT of files and a LOT of jobs... this had serious performance issues. upstreamCulprits和blame-upstream似乎都需要指纹识别,我们宁愿不要因为我们有很多文件和很多工作......这有严重的性能问题。

we solved our problem with the BlameSubversion plugin (https://wiki.jenkins-ci.org/display/JENKINS/BlameSubversion). 我们用BlameSubversion插件解决了我们的问题(https://wiki.jenkins-ci.org/display/JENKINS/BlameSubversion)。 it apparently copies the changelog.xml from the upstream project that triggered this job, and so when this job fails and looks for users who broke the build in the changelog, it can find them, and they also appear in the changelog. 它显然从触发此作业的上游项目中复制changelog.xml,因此当此作业失败并查找在更改日志中中断构建的用户时,它可以找到它们,并且它们也会出现在更改日志中。

so we were very happy, about svn. 关于svn,我们非常高兴。 now, we migrated to git. 现在,我们迁移到git。 there is no Blame Git plugin. 没有Blame Git插件。 we don't mind writing one. 我们不介意写一个。 we just need to understand if we should. 我们只需要了解是否应该。 people have been using git and jenkins together for quite some time. 人们一直在使用git和jenkins一段时间。 we can't be the first to run into this difficulty... 我们不能成为第一个遇到这个困难的人......

thanks, Nathan. 谢谢,内森。

This is the way I do it with Clearcase, it should be pretty similar on svn. 这是我使用Clearcase的方式,它应该在svn上非常相似。 In the area where you enter the list of addresses to receive the email add the following: 在您输入要接收电子邮件的地址列表的区域中,添加以下内容:

, ${SCRIPT, script="committers.groovy"} ,$ {SCRIPT,script =“committers.groovy”}

Create a new script, committers.groovy in $JENKINS_HOME/email-templates with something like the following: 使用以下内容在$ JENKINS_HOME / email-templates中创建一个新脚本committers.groovy:

// the goal is to find the top level job which should contain the changelist
def upstreamBuild = null
def cause = build.causes.find {
    if(it instanceof hudson.model.Cause.UpstreamCause) {
        return true 
    }
    return false
}

try {
    while(cause != null) {
        upstreamBuild = hudson.model.Hudson.instance.getItem(cause.upstreamProject).getBuildByNumber(cause.upstreamBuild)
        if(upstreamBuild == null) {
            break;
        }
        cause = upstreamBuild.causes.find {
            if(it instanceof hudson.model.Cause.UpstreamCause) {
                return true 
            }
            return false
        }
    }   
} catch(e) {
    // do nothing
}

// now we loop through the changeset and add all the users to a list
committers = []

if(upstreamBuild != null && upstreamBuild.changeSet != null) {
    upstreamBuild.changeSet.each() { cs ->
        if(cs.user != null) {
            committers.add(cs.user)
        }
    }
}

committers.unique().join(',')

This will generate a string which will replace the ${SCRIPT} content token with the list of committers from the upstream job. 这将生成一个字符串,该字符串将$ {SCRIPT}内容标记替换为上游作业的提交者列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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