Created
January 11, 2023 18:22
-
-
Save pwalkr/3c0fe61464872fd83544cf0c801c7f6d to your computer and use it in GitHub Desktop.
Extract file credential from Jenkins using 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 java.nio.charset.StandardCharsets | |
import org.apache.commons.io.IOUtils | |
// https://stackoverflow.com/questions/57107486/how-to-read-jenkins-credentials-at-folder-level | |
def folder = Jenkins.instance.getItems(com.cloudbees.hudson.plugins.folder.Folder).find({ | |
// TODO handle sub-folders as required | |
it.getFullName() == 'folder-name' | |
}) | |
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( | |
com.cloudbees.plugins.credentials.Credentials.class, | |
// Or just Jenkins.instance for global credentials | |
folder, | |
null, | |
null | |
); | |
found = creds.find({ | |
it.id == 'credentials-id' | |
}) | |
println "$found.id\n${found.getFileName()}\n$found.description\n" + IOUtils.toString(found.getContent(), StandardCharsets.UTF_8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment