Created
June 8, 2021 16:08
-
-
Save briceburg/67b35e4994d1a162355171e7ba859384 to your computer and use it in GitHub Desktop.
Print content of secret files from the Jenkins Credentials Store
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.domains.Domain; | |
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl; | |
// | |
// modify fileName to match the filename of the secret(s) you want to print. | |
// (ID would probably be more helpful... yay stack overflow copy pasta) | |
// alternatively comment out the filter [line 15] to dump all secret files. | |
// | |
def fileName = "secrets.env" | |
SystemCredentialsProvider.getInstance().getCredentials().stream(). | |
filter { cred -> cred instanceof FileCredentialsImpl }. | |
map { fileCred -> (FileCredentialsImpl) fileCred }. | |
filter { fileCred -> fileName.equals( fileCred.getFileName() ) }. | |
forEach { fileCred -> | |
String s = new String( fileCred.getSecretBytes().getPlainData() ) | |
println "" | |
println "XXXXXX BEGIN a secret file with id=" + fileCred.getId() + " fileName=" + fileName + " XXXXXXXXXXXX" | |
println s | |
println "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! Another way to go about this is to just create a job that prints the contents of the secret file: