0

We are currently configuring our email-ext plugin in Jenkins manually (as documented). For various reasons, we'd like to move this to a script being run (using the jobDsl step). Probably most importantly, we need to be able to configure the smtp password programmatically and not requiring that someone paste it into a gui.

This doesn't seem to be documented anywhere. I've tried looking around in the email-ext plugin's source code, and ended up with this incomplete groovy-snippet:

import jenkins.model.Jenkins
import java.net.URL

ExtendedEmailPublisherDescriptor descr = ExtendedEmailPublished.getDescriptor()
MailAccount mailAccount = descr.getMailAccount()
withCredentials(...) {
    mailAccount.setSmtpPassword(theCredentials)
}
...

I know too little about Jenkins plugins to know if I'm on the right track here.

JesperE
  • 63,317
  • 21
  • 138
  • 197

1 Answers1

0

This turned out to work for me:

import hudson.plugins.emailext.*

String credentialsId = "..."
String smtpHost = "..."
String smtpPort = "..."
boolean useTls = true

ExtendedEmailPublisherDescriptor descr = ExtendedEmailPublisher.descriptor()
MailAccount mailAccount = descr.getMailAccount()
mailAccount.setSmtpHost(smtpHost)
mailAccount.setSmtpPort(smtpPort)
mailAccount.setUseTls(useTls)
mailAccount.setCredentialsId(credentialsId)
JesperE
  • 63,317
  • 21
  • 138
  • 197