How do I configure the email-ext-plugin from a JobDsl script?

90 views Asked by At

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.

1

There are 1 answers

0
JesperE On

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)