Skip to content

Instantly share code, notes, and snippets.

@ndeloof
Created January 23, 2015 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ndeloof/58e75b275fc72e0c7c23 to your computer and use it in GitHub Desktop.
Save ndeloof/58e75b275fc72e0c7c23 to your computer and use it in GitHub Desktop.
Migrate Subversion crendentials
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.common.*;
import hudson.security.ACL
import hudson.scm.SubversionSCM
def jenkins = Jenkins.instance
jenkins.allItems.each { job ->
def scm = job.scm;
boolean found = false;
if (scm instanceof hudson.scm.SubversionSCM) {
def modules = scm.locations.collect { module ->
def credentials = CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class,
job.parent,
ACL.SYSTEM,
URIRequirementBuilder.fromUri(module.remote).build())
if (credentials.size() == 1) {
def id = credentials.get(0).id
println "credentials for $job.name / $module.remote is $id"
found = true;
module = module.withCredentialsId(id)
}
return module
}
if (found) {
scm = new SubversionSCM(modules, scm.workspaceUpdater, scm.browser, scm.excludedRegions, scm.excludedUsers,
scm.excludedRevprop, scm.excludedCommitMessages, scm.includedRegions, scm.ignoreDirPropChanges,
scm.filterChangelog, scm.additionalCredentials)
job.setScm(scm)
}
println modules.credentialsId
}
}
""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment