I'm trying to change the Stash repo browser URL for all my jobs (about 200 jobs), i've managed to change the ssh URL.
I'm doing this using a groovy script, and I'm executing it via the Script Console in Jenkins.
Here's a short snippet from script:
def OLD_GIT_URL = "old_url"
def NEW_GIT_URL = "new_url"
def OLD_STASH_REPO_URL_BROWSER = "oldStash/stash"
def allJobs = Jenkins.instance.getItems()
allJobs.each { job ->
def jobScm = job.getScm()
if (jobScm instanceof GitSCM) {
def oldScm = jobScm
// println "${job.getName()} -> It has git in it"
def git_url = jobScm.userRemoteConfigs[0].url
println "${job.getName()} -> ${git_url}"
def new_git_url = git_url.replaceAll(OLD_GIT_URL, NEW_GIT_URL)
println "The replace url is: ${new_git_url}"
// Uncomment
//jobScm.userRemoteConfigs[0].url = new_git_url
// We have a lot of jobs which contains the repo url
if (jobScmBrowser instanceof Stash){
def repo_url = jobScmBrowser.getRepoUrl()
println "${job.getName()} --> ${repo_url}"
new_repo_url = repo_url.replaceAll(OLD_STASH_REPO_URL_BROWSER, NEW_GIT_URL)
println "The replace repo url is: ${new_repo_url}"
// TODO: Replace the old url with new one
// I can't change the repo url using this property, it's private!!
//jobScmBrowser.repoUrl = new_repo_url
}
else {
println "${job.getName()} --> Not a stash browser"
}
}
else {
println "${job.getName()} -> No git in it"
}
}
因此,我通过创建一个新的Stash对象解决了:
jobScmBrowser.browser = new hudson.plugins.git.browser.Stash(new_repo_url)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.