Last active
March 14, 2022 09:51
-
-
Save jonesbusy/6a6fc7281776ee4b058862017cac2e3b to your computer and use it in GitHub Desktop.
jenkins_retrieve_credential.groovy
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
// Token/String | |
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl.class, Jenkins.instance, null, null).findAll {it.id == id}[0].secret.value) | |
// SSH key | |
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey.class, Jenkins.instance, null, null).findAll {it.id == id}[0].getPrivateKey()) | |
// Username password | |
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials.class, Jenkins.instance, null, null).findAll {it.id == id}[0].username) | |
println(com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials.class, Jenkins.instance, null, null).findAll {it.id == id}[0].password) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment