Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save saquibtmf/d3807ad2cca66455a09f6a7527c2478c to your computer and use it in GitHub Desktop.
Save saquibtmf/d3807ad2cca66455a09f6a7527c2478c to your computer and use it in GitHub Desktop.
Print content of secret files from the Jenkins Credentials Store
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