Forked from timja/jenkins-dump-credentials.groovy
Last active
March 23, 2021 18:49
-
-
Save muggenhor/7c3ec2464c7e20b12d7f5f988f94b5a6 to your computer and use it in GitHub Desktop.
Dump jenkins credentials - use in script console
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
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