Last active
December 27, 2019 18:12
-
-
Save conclusionlogic/ba8c054ecffcfdadc91c4a5c9df8def6 to your computer and use it in GitHub Desktop.
[print jenkins creds] for JCasC #jenkins #groovy #JCasC #credentials
This file contains hidden or 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
| #!/usr/bin/env groovy | |
| import jenkins.model.* | |
| import com.cloudbees.plugins.credentials.* | |
| import com.cloudbees.plugins.credentials.impl.* | |
| import com.cloudbees.plugins.credentials.domains.* | |
| import com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey | |
| import org.jenkinsci.plugins.plaincredentials.StringCredentials | |
| import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl | |
| // set Credentials domain name (null means is it global) | |
| domainName = null | |
| credentialsStore = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0]?.getStore() | |
| domain = new Domain(domainName, null, Collections.<DomainSpecification>emptyList()) | |
| credentialsStore?.getCredentials(domain).each{ credential-> | |
| if(credential instanceof com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey) | |
| println(""" - basicSSHUserPrivateKey: | |
| scope: ${credential.scope} | |
| username: ${credential.username} | |
| passphrase: ${credential.passphrase} | |
| description: "${credential.description}" | |
| privateKeySource: | |
| directEntry: | |
| privateKey: '${credential.privateKeySource.privateKey}' | |
| id: ${credential.id}""") | |
| else if (credential instanceof com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl) | |
| println(""" - usernamePassword: | |
| scope: ${credential.scope} | |
| id: ${credential.id} | |
| username: ${credential.username} | |
| description: "${credential.description}" | |
| password: ${credential.password}""") | |
| else if (credential instanceof StringCredentials) | |
| println(""" - string: | |
| scope: ${credential.scope} | |
| secret: '${credential.secret}' | |
| description: "${credential.description}" | |
| id: ${credential.id}""") | |
| //else if (credential instanceof FileCredentialsImpl) | |
| // println(""" - file: | |
| // scope: ${credential.scope} | |
| // id: ${credential.id} | |
| // description: "${credential.description}" | |
| // data: '${credential.content}' | |
| // fileName: ${credential.fileName}""") | |
| else | |
| println("something else: ${credential.id}") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment