Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save muggenhor/7c3ec2464c7e20b12d7f5f988f94b5a6 to your computer and use it in GitHub Desktop.
Save muggenhor/7c3ec2464c7e20b12d7f5f988f94b5a6 to your computer and use it in GitHub Desktop.
Dump jenkins credentials - use in script console
import com.cloudbees.plugins.credentials.*
import com.cloudbees.plugins.credentials.common.*
import com.cloudbees.plugins.credentials.domains.*
import com.cloudbees.plugins.credentials.impl.*
import com.cloudbees.jenkins.plugins.sshcredentials.impl.*
import org.jenkinsci.plugins.plaincredentials.impl.*
final domain = Domain.global()
final store = SystemCredentialsProvider.instance.store
for (credential in store.getCredentials(domain)) {
if (credential instanceof UsernamePasswordCredentialsImpl) {
println("${credential.id}: ${credential.username} ${credential.password.plainText}")
} else if (credential instanceof StringCredentialsImpl) {
println("${credential.id}: ${credential.secret.plainText}")
} else if (credential instanceof BasicSSHUserPrivateKey) {
println("${credential.id}: ${credential.username}${credential.passphrase != null ? ':' + credential.passphrase : ''}\n${credential.privateKey}")
} else if (credential.getClass().toString() == "class com.microsoft.azure.util.AzureCredentials") {
println("AzureCred: ${credential.subscriptionId} ${credential.clientId} ${credential.plainClientSecret} ${credential.tenant}")
} else if (credential.getClass().toString() == "class org.jenkinsci.plugins.github_branch_source.GitHubAppCredentials") {
println("${credential.id} ${credential.username}\n${credential.privateKey.plainText}")
} else {
println("${credential.id} ${credential.class}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment