我有一个 Jenkins 管道工作,它检查三个存储库。
当构建失败时,根据失败的位置,我想向导致最后一次提交/更改的开发人员发送电子邮件。
我可以用这个检索作者的全名:
def changeSet = script.currentBuild.changeSets[0];
Set authors = [];
if (changeSet != null) {
for (change in changeSet.items) {
authors.add(change.author.fullName)
}
}
但我想不通:最佳答案
在此处查看更多信息:
How to get e-mail address of current Jenkins user to use in groovy script
echo 'author email:' + change.author.getProperty(hudson.tasks.Mailer.UserProperty.class).getAddress()
但它需要禁用 groovy 沙箱 :(
可能的解决方案已将此添加到 Jenkins 管道共享库 :https://jenkins.io/doc/book/pipeline/shared-libraries/
像这样:
$ cat GetUserEmail.groovy
#!/usr/bin/groovy
def call(body) {
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
def User = config.get('user')
return User.getProperty(hudson.tasks.Mailer.UserProperty.class).getAddress()
}
并像这样使用:
def changeSet = script.currentBuild.changeSets[0];
Set authors = [];
if (changeSet != null) {
for (change in changeSet.items) {
authors.add(GetUserEmail{user=change.author})
}
}
关于Jenkins 管道 currentBuild.changeSets 和检索每个存储库的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46070618/