Last active
June 21, 2020 10:32
-
-
Save midnite81/0f4d07ff17a9b2fa866abd7bfbac80db to your computer and use it in GitHub Desktop.
A script to retrieve variables from Jenkins
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; | |
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