DenCowboy DenCowboy - 6 months ago 66
Groovy Question

How to use global groovy variable in external bash script

This is what I have in groovy:

sh 'echo "'+params.TEST+'"'
echo params.TEST


Both returns 'hello world' which is what I'm expecting.
Now I want to use the variable in an external bash script
test.sh
:

#!/bin/bash
echo "'+params.TEST+'"


I extend my groovy script:

sh 'echo "'+params.TEST+'"'
echo params.TEST
sh './test.sh'


But the last command, the execution of the script is not printing my parameter. What am I missing here? How can I make it work

Answer Source

You can try passing it as an argument to the shell script eg.

sh 'echo "'+params.TEST+'"'
echo params.TEST
sh './test.sh "' +params.TEST + '"'

And use the argument in the shell script as

#!/bin/bash
echo $1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download