Migration Path for Jenkins Subversion Plugin from Version 1.53 to 2.2

Introduction

Jenkins Subversion Plugin changes its credential management. Before version 2.2 you had to set your Subversion credential globally depend on domain name. In version 2.2 it's changed. The credential management is still central but now you have to configure in every job which credential the job has to use for Subversion authentication . If you have many jobs, you don't want to touch every job to change the Subversion configuration. A Groovy script for Jenkins Script Console [1] can help. In the next section I will describe how the migration path looks like.

Migration Path

  1. Update the Subversion Plugin in your Jenkins instance to version 2.2.
  2. Add your Subversion credential to the global credential store:
    1. Go to Jenkins -> Credential -> Global credentials -> Add credential
    2. Add your credential. The scope has to be global.
  3. Go to the installation path of your Jenkins instance and open the file credential.xml.
  4. Search in credential.xml for the element <com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl> that contains your above set credential and copy the value of the element <id> . Example:
1<com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
2  <scope>GLOBAL</scope>
3  <id>63c3793c-e3fb-49eb-b45b-f6f8e7364876</id>
4  <description></description>
5  <username>jenkinssvnuser</username>
6  HyDUenzpyDkbL9xMoQ0pxdK10l20VkXKEiy4+ZnjL9c=
7</com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl>
  1. Go to the Jenkins Script Console and run following Groovy script. Assign your credential id to the variable credentialId before running the script.
 1def credentialId = '63c3793c-e3fb-49eb-b45b-f6f8e7364876'
 2
 3Hudson.instance.items.each { item ->
 4
 5if(item.scm instanceof hudson.scm.SubversionSCM) {
 6  println("JOB : "+item.name)
 7
 8  def newLocations = new ArrayList()
 9
10  item.scm.locations.each {location ->
11  newLocations.add(new hudson.scm.SubversionSCM.ModuleLocation(location.remote, credentialId, location.local, location.depthOption,location.ignoreExternalsOption))
12}
13
14def newScm = new hudson.scm.SubversionSCM(newLocations, item.scm.workspaceUpdater,
15item.scm.browser, item.scm.excludedRegions, item.scm.excludedUsers, item.scm.excludedRevprop, item.scm.excludedCommitMessages,
16item.scm.includedRegions, item.scm.ignoreDirPropChanges, item.scm.filterChangelog, item.scm.additionalCredentials)
17
18item.scm = newScm
19item.save()
20println("\n=======\n")
21}
  1. Finish.

This script is tested with Jenkins version 1.555 and Jenkins Subversion Plugin version 2.2. On Github [2] you can find more Groovy script for Jenkins Script Console.