Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonesbusy/6a6fc7281776ee4b058862017cac2e3b to your computer and use it in GitHub Desktop.
Save jonesbusy/6a6fc7281776ee4b058862017cac2e3b to your computer and use it in GitHub Desktop.
jenkins_retrieve_credential.groovy
// Token/String
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl.class, Jenkins.instance, null, null).findAll {it.id == id}[0].secret.value)
// SSH key
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.class, Jenkins.instance, null, null).findAll {it.id == id}[0].getPrivateKey())
// Username password
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials.class, Jenkins.instance, null, null).findAll {it.id == id}[0].username)
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials.class, Jenkins.instance, null, null).findAll {it.id == id}[0].password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment