Forked from jbouse/jenkins-dump-credentials.groovy
Last active
August 13, 2020 19:18
-
-
Save sahal/f7323c297283175b91f987a79a5a8534 to your computer and use it in GitHub Desktop.
Dump jenkins credentials - use in script console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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