Get Jenkins secret values with script console

devops-cicd

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

Leave a Reply

Your email address will not be published. Required fields are marked *

โ˜• Support us ยท ๐Ÿ’ณ Monobank