Last active
August 19, 2024 06:20
-
-
Save renan-alm/9747c6a3942e4401aedba39d35616b7b to your computer and use it in GitHub Desktop.
Gist to get all credentials from a Jenkins instance
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
// Source: https://stackoverflow.com/questions/34795050/how-do-i-list-all-of-my-jenkins-credentials-in-the-script-console | |
// To be used at a jenkins_instance_url/script, example https://jenkins.corp.net/script | |
import java.nio.charset.StandardCharsets; | |
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( | |
com.cloudbees.plugins.credentials.Credentials.class | |
) | |
for (c in creds) { | |
println(c.id) | |
if (c.properties.description) { | |
println(" description: " + c.description) | |
} | |
if (c.properties.username) { | |
println(" username: " + c.username) | |
} | |
if (c.properties.password) { | |
println(" password: " + c.password) | |
} | |
if (c.properties.passphrase) { | |
println(" passphrase: " + c.passphrase) | |
} | |
if (c.properties.secret) { | |
println(" secret: " + c.secret) | |
} | |
if (c.properties.secretBytes) { | |
println(" secretBytes: ") | |
println("\n" + new String(c.secretBytes.getPlainData(), StandardCharsets.UTF_8)) | |
println("") | |
} | |
if (c.properties.privateKeySource) { | |
println(" privateKey: " + c.getPrivateKey()) | |
} | |
if (c.properties.apiToken) { | |
println(" apiToken: " + c.apiToken) | |
} | |
if (c.properties.token) { | |
println(" token: " + c.token) | |
} | |
if (c.properties.subscriptionId) { | |
println(" subscriptionId: " + c.subscriptionId) | |
} | |
if (c.properties.clientId) { | |
println(" clientId: " + c.clientId) | |
} | |
if (c.properties.tenant) { | |
println(" tenant: " + c.tenant) | |
} | |
if (c.properties.clientSecret) { | |
println(" clientSecret: " + c.clientSecret) | |
} | |
if (c.properties.plainClientSecret) { | |
println(" plainClientSecret: " + c.plainClientSecret) | |
} | |
println("") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment