Created
December 19, 2019 12:10
-
-
Save pjdarton/8f5db048a259f9f6cb5fe683356a3783 to your computer and use it in GitHub Desktop.
Lists all Jenkins credentials. Requires admin access to 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
import com.cloudbees.hudson.plugins.folder.Folder | |
import com.cloudbees.jenkins.plugins.sshcredentials.SSHUserPrivateKey | |
import com.cloudbees.plugins.credentials.Credentials | |
import com.cloudbees.plugins.credentials.CredentialsProvider | |
import com.cloudbees.plugins.credentials.common.PasswordCredentials | |
import com.cloudbees.plugins.credentials.common.UsernameCredentials | |
import jenkins.plugins.openstack.compute.auth.OpenstackCredentialv3 | |
import org.jenkinsci.plugins.plaincredentials.StringCredentials | |
Set<Credentials> getAllCredentials() { | |
def result = new HashSet<Credentials>(); | |
result.addAll(CredentialsProvider.lookupCredentials(Credentials.class)) | |
Jenkins.instance.getAllItems(Folder.class).each{ f -> | |
result.addAll(CredentialsProvider.lookupCredentials(Credentials.class, f)) | |
} | |
result | |
} | |
def allCredentials = getAllCredentials() | |
for (c in allCredentials) { | |
println("ID: " + c.id) | |
println(" Class: " + c.class.simpleName) | |
println(" Description: " + c.description) | |
if (c instanceof UsernameCredentials ) { | |
println(" Username: " + c.username) | |
} | |
if (c instanceof PasswordCredentials ) { | |
println(" Password: " + c.password) | |
} | |
if (c instanceof OpenstackCredentialv3 ) { | |
println(" UserDomain: " + c.userDomain) | |
println(" ProjectName: " + c.projectName) | |
println(" ProjectDomain: " + c.projectDomain) | |
} | |
if (c instanceof SSHUserPrivateKey ) { | |
println(" Passphrase: " + c.passphrase) | |
println(" PrivateKeys: " + c.privateKeys) | |
} | |
if (c instanceof StringCredentials ) { | |
println(" String: " + c.secret?.plainText) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment