Created
April 25, 2022 08:10
-
-
Save ndkoo/74819e68ea363951873742d1406106d1 to your computer and use it in GitHub Desktop.
Jenkins secret dump
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.CredentialsProvider | |
import com.cloudbees.plugins.credentials.Credentials | |
import com.cloudbees.plugins.credentials.domains.Domain | |
import jenkins.model.Jenkins | |
def indent = { String text, int indentationCount -> | |
def replacement = "\t" * indentationCount | |
text.replaceAll("(?m)^", replacement) | |
} | |
Jenkins.get().allItems().collectMany{ CredentialsProvider.lookupStores(it).toList()}.unique().forEach { store -> | |
Map<Domain, List<Credentials>> domainCreds = [:] | |
store.domains.each { domainCreds.put(it, store.getCredentials(it))} | |
if (domainCreds.collectMany{ it.value}.empty) { | |
return | |
} | |
def shortenedClassName = store.getClass().name.substring(store.getClass().name.lastIndexOf(".") + 1) | |
println "Credentials for store context: ${store.contextDisplayName}, of type $shortenedClassName" | |
domainCreds.forEach { domain , creds -> | |
println indent("Domain: ${domain.name}", 1) | |
creds.each { cred -> | |
cred.properties.each { prop, val -> | |
println indent("$prop = \"$val\"", 2) | |
} | |
println indent("-----------------------", 2) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment