Skip to content

Instantly share code, notes, and snippets.

@sahal
Forked from jbouse/jenkins-dump-credentials.groovy
Last active August 13, 2020 19:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sahal/f7323c297283175b91f987a79a5a8534 to your computer and use it in GitHub Desktop.
Save sahal/f7323c297283175b91f987a79a5a8534 to your computer and use it in GitHub Desktop.
Dump jenkins credentials - use in script console
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import org.jenkinsci.plugins.plaincredentials.impl.*
domain = Domain.global()
store = SystemCredentialsProvider.getInstance().getStore()
for (credential in store.getCredentials(domain)) {
if (credential instanceof UsernamePasswordCredentialsImpl) {
println "----------"
println "- usernamePassword:\n description: " + credential.description + "\n id: " + credential.id + "\n scope: " + credential.scope + "\n username: " + credential.username + "\n password: " + credential.password.plainText + "\n"
} else if (credential instanceof StringCredentialsImpl) {
println "----------"
println "- SecretText: " + credential.id + " " + credential.secret.plainText
} else if(credential instanceof FileCredentialsImpl) {
println "----------"
decrypted_file = new String(com.cloudbees.plugins.credentials.SecretBytes.getPlainData(credential.secretBytes), "ASCII")
println "- File: " + credential.id + " " + credential.fileName + "\n" + decrypted_file
} else {
// use the following information to add other credential types to this large if statement
println credential.class
println credential.class.collect{c -> [c.declaredMethods,c.methods]}.flatten()*.name as SortedSet
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment