Last active
January 18, 2020 08:02
-
-
Save ThabetAmer/e39a7b12fb87caa11c2f8689bd929dfa to your computer and use it in GitHub Desktop.
Groovy Function for Jenkins pipelines
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
#!/usr/bin/env groovy | |
/** | |
* Reads environment variables from a property file, and loads them into Jenkins ENV | |
* @author [email protected] | |
* @since Jenkins 2.204.1 | |
* @param String path | |
* @return String array | |
* | |
* Example property file: | |
* # Environment variables for Jenkins builds | |
* VAR1=SAMPLE-VAR | |
* | |
*/ | |
def loadEnvvars(String path) { | |
try { | |
Map envvars = readProperties(interpolate: true, file: path) ?: null | |
if (!envvars) { throw new Exception("unable to read properties file " + path) } | |
keys = envvars.keySet() | |
for(key in keys) { | |
value = envvars["${key}"] | |
env."${key}" = "${value}" | |
} | |
return envvars | |
} | |
catch(err) { | |
echo "ERROR: caught in loadEnvvars ${err}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment