Created
January 23, 2012 16:39
-
-
Save cescoffier/1664154 to your computer and use it in GitHub Desktop.
Update Jabber server in Jenkins builds.When switching to another Jabber server, builds needs to be updated to use the new Jabber server, i.e. [email protected] needs to become [email protected] groovy script just updates the configuration.
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.* | |
import hudson.maven.* | |
import hudson.maven.reporters.* | |
import hudson.tasks.* | |
def instance = hudson.model.Hudson.instance; | |
// To update to match the old server and new configuration | |
def oldServer = "akquinet.dnsalias.com"; | |
def newServer = "chat.spree.de"; | |
for (project in instance.items) { | |
// Regular non-maven project | |
for (publisher in project.getPublishersList()) { | |
if (publisher.class.name.contains("JabberPublisher")) { | |
println("Jabber publisher found for " + project.name); | |
def newTargets = new ArrayList(); | |
for (target in publisher.getNotificationTargets()) { | |
if (target.value.contains(oldServer)) { | |
original = target.value; | |
newValue = target.value.replace(oldServer, newServer) | |
hudson.plugins.im.DefaultIMMessageTarget newTarget = new hudson.plugins.im.DefaultIMMessageTarget(newValue) | |
println("Replacing notification target from " + original + " to " + newTarget + " in " + project.name); | |
newTargets.add(newTarget); | |
} else { | |
newTargets.add(target); | |
} | |
} | |
println("Publications sent to " + newTargets); | |
publisher.setNotificationTargets(newTargets); | |
project.save(); | |
} | |
} | |
// Maven projects | |
if (project instanceof MavenModuleSet) { | |
for (publisher in project.reporters) { | |
if (publisher.class.name.contains("JabberPublisher")) { | |
println("Jabber publisher found for " + project.name); | |
def newTargets = new ArrayList(); | |
for (target in publisher.getNotificationTargets()) { | |
if (target.value.contains(oldServer)) { | |
original = target.value; | |
newValue = target.value.replace(oldServer, newServer) | |
hudson.plugins.im.DefaultIMMessageTarget newTarget = new hudson.plugins.im.DefaultIMMessageTarget(newValue) | |
println("Replacing notification target from " + original + " to " + newTarget + " in " + project.name); | |
newTargets.add(newTarget); | |
} else { | |
newTargets.add(target); | |
} | |
} | |
println("Publications sent to " + newTargets); | |
publisher.setNotificationTargets(newTargets); | |
project.save(); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment