-
-
Save mika/4a80aff5ee6b4bcdc13f to your computer and use it in GitHub Desktop.
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 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