Skip to content

Instantly share code, notes, and snippets.

@rbellamy
Last active February 14, 2017 00:03
Show Gist options
  • Save rbellamy/15b542e5d70f95717642c99fdfaa2f25 to your computer and use it in GitHub Desktop.
Save rbellamy/15b542e5d70f95717642c99fdfaa2f25 to your computer and use it in GitHub Desktop.
Env Overwritten in Jenkins CPS Global Library
#!/usr/bin/env groovy
node {
echo "env - ${env}"
withTest {
args = "testing 1 2 3"
}
}
Running on master in /var/lib/jenkins/workspace/tum_jenkinsfile-test_master-QDJUBELK35RLWCXETJEDXKBXGYGVRLIBVHHVO25OOHHUYVD5BOGQ
[Pipeline] {
[Pipeline] echo
env - org.jenkinsci.plugins.workflow.cps.EnvActionImpl@5641c899
[Pipeline] echo
env1 - org.jenkinsci.plugins.workflow.cps.EnvActionImpl@5641c899
[Pipeline] timeout
Timeout set to expire in 3 hr 0 min
[Pipeline] {
[Pipeline] echo
env1.1 - org.jenkinsci.plugins.workflow.cps.EnvActionImpl@5641c899
[Pipeline] withEnv
[Pipeline] {
[Pipeline] echo
env1.2 - org.jenkinsci.plugins.workflow.cps.EnvActionImpl@5641c899
[Pipeline] echo
env2 - null
[Pipeline] echo
CA_KEY_PEM - null
[Pipeline] echo
env3 - null
[Pipeline] wrap
[Pipeline] {
[Pipeline] sh
[tum_jenkinsfile-test_master-QDJUBELK35RLWCXETJEDXKBXGYGVRLIBVHHVO25OOHHUYVD5BOGQ] Running shell script
+ echo testing 1 2 3
testing 1 2 3
[Pipeline] }
[Pipeline] // wrap
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // timeout
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
GitHub has been notified of this commit’s build result
Finished: SUCCESS
def call(body) {
// evaluate the body block, and collect configuration into the object
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
echo "env1 - ${env}"
String args = config.args
List cmdEnv = config.cmdEnv
timeout(time: 180, unit: 'MINUTES') {
//noinspection GroovyAssignabilityCheck
withTestEnv {
envVars = cmdEnv
test = {
echo "env2 - ${env}"
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
sh "echo ${args}"
sh "env"
}
}
}
}
}
#!/usr/bin/env groovy
def call(body) {
// evaluate the body block, and collect configuration into the object
def config = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = config
body()
List envVars = config.envVars
Closure test = config.test
echo "env1.1 - ${env}"
// Set JAVA_HOME, MAVEN_HOME and special PATH variables for the tools we're using.
List testEnv = ["VAL=value"]
// Add any additional environment variables.
if (envVars) {
testEnv.addAll(envVars)
}
// Invoke the body closure we're passed within the environment we've created.
withEnv(testEnv) {
echo "env1.2 - ${env}"
test.call()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment