Skip to content

Instantly share code, notes, and snippets.

@hgomez
Last active November 8, 2021 12:01
Show Gist options
  • Select an option

  • Save hgomez/8757649 to your computer and use it in GitHub Desktop.

Select an option

Save hgomez/8757649 to your computer and use it in GitHub Desktop.
Jenkins Groovy script to set CredentialsId
import hudson.model.*
import hudson.maven.*
import hudson.tasks.*
import hudson.scm.*
def match_url = "http://svn.mycorp.com/svn/devops"
for(item in Hudson.instance.items) {
hasClaim = false;
if (item.scm instanceof SubversionSCM)
{
for(location in item.scm.locations) {
if (location.remote.startsWith(match_url)) {
println("\n@@@@@@@@@@@@@@@@@")
println("\njob $item.name")
println("\n@@@@@@@@@@@@@@@@@")
println("\nlocation $location.remote")
credid = location.credentialsId
if (credid != null)
println("\ncredid $credid")
}
}
}
}
@sathishc58
Copy link

Please post the code to set the 'credentials id' as I've been searching for quite sometime now. This code deals with fetching the 'credentials id' Thanks in advnace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment