How is it possible to export a variable from the sh context of sh context to the groovy context of the jenkins pipline job?
Pipeline Code:
node {
echo 'Hello World'
sh 'export VERSION="v$(date)"'
echo env.VERSION
}
outupt:
[Pipeline] sh
[test-pipeline] Running shell script
++ date
+ export 'VERSION=vThu Dec 1 12:14:40 CET 2016'
+ VERSION='vThu Dec 1 12:14:40 CET 2016'
[Pipeline] echo`enter code here`
null
i am using Jenkins ver. 2.34
update: there is the possibility to write the variable to a temporary file and read it later. This looks totally like a hack to me. It is not "thread-safe" by default when using parallel builds and does not scale if you need to export multiple variable in one run. Is there a proper way to do this?
I hope this will help.
node('master'){
stage('stage1'){
def commit = sh (returnStdout: true, script: '''echo hi
echo bye | grep -o "e"
date
echo lol''').split()
echo "${commit[-1]} "
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With