Configure extended email plugin properly
API was changed so base Mailer is now not mirrored by ExtMail plugin.
We have to handle them separately now.
PROD-36691
Change-Id: I1166fd84a7e8a36ce3874831a154ac3271fc4a69
diff --git a/jenkins/files/groovy/smtp.template b/jenkins/files/groovy/smtp.template
index baa55f4..2010df4 100644
--- a/jenkins/files/groovy/smtp.template
+++ b/jenkins/files/groovy/smtp.template
@@ -11,41 +11,65 @@
def instance = Jenkins.instance
Boolean changed = false
- void configureMailer(params) {
- for (mailer in [instance.getDescriptor("hudson.plugins.emailext.ExtendedEmailPublisher"),
- instance.getDescriptor("hudson.tasks.Mailer")]) {
- if (mailer.smtpHost != params.host) {
- mailer.smtpHost = params.host
- changed = true
- }
- if (mailer.smtpPort != params.port.toString()) {
- mailer.smtpPort = params.port
- changed = true
- }
- if (mailer.charset != params.charset) {
- mailer.charset = params.charset
- changed = true
- }
- if (mailer.useSsl != params.ssl) {
- mailer.useSsl = params.ssl
- changed = true
- }
- if (mailer.smtpAuthUsername != params.username) {
- mailer.smtpAuthUsername = params.username
- changed = true
- }
- if (mailer.smtpAuthPassword.toString() != params.password) {
- mailer.smtpAuthPassword = hudson.util.Secret
- .fromString(params.password)
- changed = true
- }
- if (params.useReplyTo &&
- mailer instanceof hudson.tasks.Mailer$DescriptorImpl &&
- mailer.replyToAddress != params.replyTo) {
- mailer.replyToAddress = params.replyTo
- changed = true
- }
+ void configureBaseMailer(params){
+ def mailer = instance.getDescriptor("hudson.tasks.Mailer")
+ if (mailer.smtpHost != params.host) {
+ mailer.smtpHost = params.host
+ changed = true
}
+ if (mailer.smtpPort != params.port.toString()) {
+ mailer.smtpPort = params.port
+ changed = true
+ }
+ if (mailer.charset != params.charset) {
+ mailer.charset = params.charset
+ changed = true
+ }
+ if (mailer.useSsl != params.ssl) {
+ mailer.useSsl = params.ssl
+ changed = true
+ }
+ if (mailer.smtpAuthUsername != params.username) {
+ mailer.smtpAuthUsername = params.username
+ changed = true
+ }
+ if (mailer.smtpAuthPassword.toString() != params.password) {
+ mailer.smtpAuthPassword = hudson.util.Secret.fromString(params.password)
+ changed = true
+ }
+ if (params.useReplyTo && mailer.replyToAddress != params.replyTo) {
+ mailer.replyToAddress = params.replyTo
+ changed = true
+ }
+ }
+
+ void configureExtMailer(params){
+ def mailer = instance.getDescriptor("hudson.plugins.emailext.ExtendedEmailPublisher")
+ if (mailer.mailAccount.smtpHost != params.host) {
+ mailer.mailAccount.smtpHost = params.host
+ changed = true
+ }
+ if (mailer.mailAccount.smtpPort != params.port.toString()) {
+ mailer.mailAccount.smtpPort = params.port
+ changed = true
+ }
+ if (mailer.mailAccount.useSsl != params.ssl) {
+ mailer.mailAccount.useSsl = params.ssl
+ changed = true
+ }
+ if (mailer.mailAccount.smtpUsername != params.username) {
+ mailer.mailAccount.smtpUsername = params.username
+ changed = true
+ }
+ if (mailer.mailAccount.smtpPassword.toString() != params.password) {
+ mailer.mailAccount.smtpPassword = hudson.util.Secret.fromString(params.password)
+ changed = true
+ }
+ }
+
+ void configureMailers(params) {
+ configureBaseMailer(params)
+ configureExtMailer(params)
}
}
@@ -55,7 +79,7 @@
def actions = new Actions(out)
-actions.configureMailer(params)
+actions.configureMailers(params)
if (actions.changed) {
actions.instance.save()