Last active
August 25, 2022 17:14
-
-
Save ripa1993/f462a2d8525dedf9e722a54ba9260dfc to your computer and use it in GitHub Desktop.
Lookup secrets in Jenkins
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
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( | |
com.cloudbees.plugins.credentials.impl.BaseStandardCredentials.class, | |
Jenkins.instance, | |
null, | |
null | |
) | |
for(c in creds) { | |
if(c instanceof com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey){ | |
println(String.format("id=%s desc=%s key=%s\n", c.id, c.description, c.privateKeySource.getPrivateKeys())) | |
} | |
else if (c instanceof com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl){ | |
println(String.format("id=%s desc=%s user=%s pass=%s\n", c.id, c.description, c.username, c.password)) | |
} | |
else if (c instanceof org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl){ | |
println(String.format("id=%s desc=%s secret=%s\n", c.id, c.description, c.secret)) | |
} | |
else if (c instanceof org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl){ | |
println(String.format("id=%s desc=%s fileName=%s secretBytes=%s\n", | |
c.id, | |
c.description, | |
c.fileName, | |
new String(com.cloudbees.plugins.credentials.SecretBytes.fromString(c.secretBytes.toString()).getPlainData()))) | |
} | |
else if (c instanceof com.cloudbees.jenkins.plugins.awscredentials.AWSCredentialsImpl){ | |
println(String.format("id=%s accessKey=%s secret=%s\n", c.id, c.accessKey, c.secretKey)) | |
} | |
else { | |
println(c.getClass()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
open https://yourjenkins/script
copy, paste, run