Skip to content

Instantly share code, notes, and snippets.

@markhuge
Created January 30, 2013 00:24
Show Gist options
  • Select an option

  • Save markhuge/4669438 to your computer and use it in GitHub Desktop.

Select an option

Save markhuge/4669438 to your computer and use it in GitHub Desktop.
Bulk Jenkins git repo configuration through Groovy interface.
// Loop through Jenkins projects, adding a git repo for any project without a repo defined.
def projects = hudson.model.Hudson.instance;
projects.getItems(hudson.model.Project).each {
proj ->
if (proj.getScm().type == "hudson.scm.NullSCM") {
proj.scm = new hudson.plugins.git.GitSCM("git://path/to/your/repo.git");
println("Project: " + proj.displayName + " SCM: " + proj.getScm().type);
}
}
// Same as above, but added logic to only update builds where the name contains 'FOO'
def projects = hudson.model.Hudson.instance
projects.getItems(hudson.model.Project).each {
proj ->
if (proj.getScm().type == "hudson.scm.NullSCM" && proj.displayName.contains('FOO')) {
proj.scm = new hudson.plugins.git.GitSCM("git://path/to/your/repo.git");
println("Project: " + proj.displayName + " SCM: " + proj.getScm().type);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment