Forked from francoisledroff/debug-jenkins-email-ext-plugins.groovy
Last active
March 25, 2019 02:09
-
-
Save jinlxz/3437d1335a6113ddecb240d35c181a08 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+pluginto 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"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hudson.model.StreamBuildListener | |
import hudson.plugins.emailext.ExtendedEmailPublisher | |
import java.io.ByteArrayOutputStream | |
def projectName = "your-project-name-here" | |
def oriProject=Jenkins.instance.getItem(projectName) | |
if(oriProject==null){ | |
println "oriProject is null, exit." | |
return 1 | |
} | |
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 = '[email protected]' // 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