Forked from briceburg/print-jenkins-secret-file-contents.groovy
Created
October 8, 2024 07:28
-
-
Save zh4n7wm/8d60dd9cd9b31ce706f2d6037aed55a1 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