This Script Console snippet enumerates Jenkins credentials and prints values for username/private-key and username/password entries. Use it only in tightly controlled administrative troubleshooting scenarios.
Script Console Example
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class,
Jenkins.instance,
null,
null
);
for (c in creds) {
println( ( c.properties.privateKeySource ? "ID: " + c.id + ", UserName: " + c.username + ", Private Key: " + c.getPrivateKey() : ""))
}
for (c in creds) {
println( ( c.properties.password ? "ID: " + c.id + ", UserName: " + c.username + ", Password: " + c.password : ""))
}
Security Warning
- This script can expose secrets in plain text output and build logs.
- Run only with strict administrative access controls.
- Prefer metadata-only inspection in normal operations.
- Rotate exposed credentials immediately after emergency diagnostics.
Official Documentation
- Jenkins Script Console: https://www.jenkins.io/doc/book/managing/script-console/
- Jenkins Credentials Plugin: https://plugins.jenkins.io/credentials/
