Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save francoisledroff/5482559 to your computer and use it in GitHub Desktop.
Save francoisledroff/5482559 to your computer and use it in GitHub Desktop.
a groovy script to test your email extension templates cf. https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin to do that just * replace the projectName and p.recipientList values in the script below * run this script through http://localhost:8080/jenkins/script ** copy and paste it ** click "run"
import hudson.model.StreamBuildListener
import hudson.plugins.emailext.ExtendedEmailPublisher
import java.io.ByteArrayOutputStream
def projectName = "your-project-name-here"
Jenkins.instance.copy(Jenkins.instance.getItem(projectName), "$projectName-Testing");
def project = Jenkins.instance.getItem(projectName)
try {
def testing = Jenkins.instance.getItem("$projectName-Testing")
def build = project.lastBuild
// or def build = project.lastFailedBuild
// see the <a href="http://javadoc.jenkins-ci.org/hudson/model/Job.html#getLastBuild()" title="Job" target="_blank">javadoc for the Job class</a>
//for other ways to get builds
def baos = new ByteArrayOutputStream()
def listener = new StreamBuildListener(baos)
testing.publishersList.each() { p ->
println(p)
if(p instanceof ExtendedEmailPublisher) {
// modify the properties as necessary here
p.recipientList = 'me@me.com' // set the recipient list while testing
// run the publisher
p.perform((AbstractBuild<?,?>)build, null, listener)
// print out the build log from ExtendedEmailPublisher
println(new String( baos.toByteArray(), "UTF-8" ))
}
}
} finally {
if(testing != null) {
// cleanup the test job
testing.delete()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment