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"
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/bb5e7122-32dc-48c7-896d-ed204995394a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to