Jenkins向所有作业添加/更新:应向默认收件人列表发送电子邮件警报
我们的jenkins已经有大约100个工作了,我想为所有工作添加可编辑的电子邮件通知,这样所有的工作都应该有电子邮件通知到默认收件人列表。正在寻找Jenkins脚本控制台的Groovy脚本,以添加或修改电子邮件通知设置Jenkins向所有作业添加/更新:应向默认收件人列表发送电子邮件警报,jenkins,groovy,jenkins-groovy,email-ext,Jenkins,Groovy,Jenkins Groovy,Email Ext,我们的jenkins已经有大约100个工作了,我想为所有工作添加可编辑的电子邮件通知,这样所有的工作都应该有电子邮件通知到默认收件人列表。正在寻找Jenkins脚本控制台的Groovy脚本,以添加或修改电子邮件通知设置 Jenkins.instance.items.each { item -> println("JOB: " + item.name) // code for setting email notification if not exist if(item.XX
Jenkins.instance.items.each { item ->
println("JOB: " + item.name)
// code for setting email notification if not exist
if(item.XXXX == null) {
println("No email notification step ")
}
else {
// code to update the current email settings
println("Set new setting")
}
item.save()
println(" done")
}
或者其他一些自动化的方式也可以。
谢谢 假设您使用的是hudson.plugins.emailext.ExtendedEmailPublisher,并且所有作业都已添加了该步骤,那么这可能包括迭代部分
// Gets all jobs and folders recursively
items = Jenkins.instance.getAllItems();
items.each { item ->
def status = ''
def base_email = ''
def ext_email = []
if (item.class.name == "hudson.model.FreeStyleProject") {
item.publishersList.findAll {it instanceof hudson.plugins.emailext.ExtendedEmailPublisher}.each { publisher ->
status = publisher.disabled
base_email=publisher.recipientList?.replaceAll("\\r|\\n", " ")
publisher.configuredTriggers?.each { entry ->
if (entry.email.recipientList) {
ext_email << "${entry.class.name.replace("hudson.plugins.emailext.plugins.trigger.", "")}: ${entry.email.recipientList?.replaceAll("\\r|\\n", " ")}"
}
}
}
if ( base_email ) {
println item.fullName + "( " + status + " )"
println " +- " + base_email
ext_email.each {
println " - " + it
}
} else {
println "# " + item.fullName
}
}
}
return
或根据需要提供同等产品
注意:扩展电子邮件插件有一个开关,用于禁用发送电子邮件禁用扩展电子邮件Publisher.disabled,所以也要报告
如果您需要添加插件,那么它将类似于:
item.PublisherList.addnew hudson.plugins.emailext.ExtendedEmailPublisher您好,感谢您的快速回复。当我尝试时,我发现了错误。。org.codehaus.groovy.control.multiplecompationerrorsException:启动失败:Script1.groovy:29:意外字符:0xFFFF@line 29,第9列。return 0假设我没有为所有作业启用可编辑的电子邮件通知步骤。如何使用groovy脚本为所有作业启用它。我想现在还可以。你能帮忙吗?我已经重新粘贴了代码;可能在零结尾是个坏角色,不需要。添加了对javadoc的引用。我在您的else部分中添加了此部分,以将电子邮件步骤添加到缺少的作业中。else{println+item.fullName//item.publishersList.removehdson.plugins.emailext.extendedmailpublisher def eep=new extendedmailpublisher;eep.recipientList=\$DEFAULT\u RECIPIENTS eep.defaultSubject=\$DEFAULT\u SUBJECT eep.defaultContent=\$DEFAULT\u CONTENT//带有一些触发器}出于某种原因,添加触发器对我不起作用……这对我不起作用,这是我的最佳解决方案。//使用某些触发器eep.configuredTriggers.addnew FailureTriggers电子邮件:new EmailType sendToRecipientList:true,正文:ExtendedEmailPublisher.PROJECT\u DEFAULT\u body\u TEXT,主题:ExtendedEmailPublisher.PROJECT\u DEFAULT\u subject\u TEXT
publisher.recipientList="someone@somewhere.com"
item.save()