Jenkins - changing Stash repo browser URL

15 views
Skip to first unread message

Alex Brodov

unread,
Dec 30, 2015, 2:46:46 PM12/30/15
to Jenkins Users

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

}
Reply all
Reply to author
Forward
0 new messages