Skip to content

Instantly share code, notes, and snippets.

@midnite81
Last active June 21, 2020 10:32
Show Gist options
  • Save midnite81/0f4d07ff17a9b2fa866abd7bfbac80db to your computer and use it in GitHub Desktop.
Save midnite81/0f4d07ff17a9b2fa866abd7bfbac80db to your computer and use it in GitHub Desktop.
A script to retrieve variables from Jenkins
import com.cloudbees.plugins.credentials.*;
import com.cloudbees.plugins.credentials.domains.Domain;
import org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl;
println "Jenkins credentials config file location=" + SystemCredentialsProvider.getConfigFile();
println ""
def fileName = "<nameOfFile>" // e.g appsettings.Development.json
SystemCredentialsProvider.getInstance().getCredentials().stream().
filter { cred -> cred instanceof FileCredentialsImpl }.
map { fileCred -> (FileCredentialsImpl) fileCred }.
filter { fileCred -> fileName.equals( fileCred.getFileName() ) }.
forEach { fileCred ->
String file = new String( fileCred.getSecretBytes().getPlainData() )
println "XXXXXX BEGIN a secret file with fileName=" + fileName + " XXXXXXXXXXXX"
println file
println "XXXXXX END a secret file with fileName=" + fileName + " XXXXXXXXXXXX"
println ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment