首页 文章

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

提问于
浏览
7

这个问题是关于如何将电子邮件发送到git提交者,这些提交者在jenkins的下游作业中破坏了集成测试,并查看下游作业中的更改列表 .

我没有尝试过我在这里写的所有东西,所以我可能是错的,这些是我遇到的代码的印象 .

显然有很多尝试回答这个问题,但没有一个看起来令人满意,所以我会详细说明 . 细节如下:

我们曾经和svn合作过 . 我们的作业层次结构是一个作业检出并编译,并触发其他作业,这些作业采用编译工件并对它们执行misc集成测试 .

需要将电子邮件发送给破坏构建的上游svn提交者 .

我们喜欢通过email-ext插件(https://wiki.jenkins-ci.org/display/JENKINS/Email-ext插件)发送电子邮件,因为它非常可定制,我们大量使用此功能 .

email ext plugin使用当前作业的changelog.xml来发现谁破坏了构建 . 由于changelog.xml是由checkout操作创建的,因此它存在于上游作业中 . 因此,email-ext似乎不知道应该向谁发送电子邮件 .

如果您决定包含罪犯,您可以使用-Dhudson.upstreamCulprits = true启动您的jenkins,这会更改email-ext的行为,但如果您不想包含罪犯,这对您没有帮助 . 此外,变更集似乎在下游作业中不可用 .

还有一个责备上游提交者插件,但它似乎不适用于email-ext .

upstreamCulprits和blame-upstream似乎都需要指纹识别,我们宁可不要因为我们有很多文件和很多工作......这有严重的性能问题 .

我们用BlameSubversion插件解决了我们的问题(https://wiki.jenkins-ci.org/display/JENKINS/BlameSubversion) . 它显然会从触发此作业的上游项目中复制changelog.xml,因此当此作业失败并查找在更改日志中中断构建的用户时,它可以找到它们,并且它们也会出现在更改日志中 .

关于svn,我们非常高兴 . 现在,我们迁移到git . 没有Blame Git插件 . 我们不介意写一个 . 我们只需要了解是否应该 . 人们一直在使用git和jenkins一段时间 . 我们不能成为第一个遇到这个困难的人......

谢谢,内森 .

1 回答

  • 7

    这是我使用Clearcase的方式,它应该在svn上非常相似 . 在您输入要接收电子邮件的地址列表的区域中,添加以下内容:

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

    使用以下内容在$ 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(',')
    

    这将生成一个字符串,该字符串将$ 内容标记替换为上游作业的提交者列表 .

相关问题