Reputation: 667
I have a Jenkins job which executes a shell script on remote server. Now I would like to send some parameters along with the shell script. Below example might get you more idea.
variable1={git-URL}
variable2={branch}
I want this parameters to be passed on to shell script which is on remote machine and should execute like below
#/usr/local/bin/check_out_code.sh <git-url> <branch>
Would be great if anyone can point me some work around for this
Thanks.
Upvotes: 3
Views: 15297
Reputation: 2933
As mentioned by @Slav you can use environment/build arguments like any other environment variable in Jenkins. One thing to remember is that they get expanded before the script is executed. If you happen to be using pipeline groovy scripts, make sure you use double quotes "
instead of single '
:
following will not work:
sh '/usr/local/bin/check_out_code.sh ${giturl} ${branch}'
following will work:
sh "/usr/local/bin/check_out_code.sh ${giturl} ${branch}"
Upvotes: 0
Reputation: 21
I have the same problem with it.
The parameters/${xx}/$xxx
are undefined in remote machine. So when your shell script executes in remote machine cannot get the correct value.
This way will fix the problem:
ssh -t server.example.com 'export MYVAR='"'$LOCALVAR'"'; mycommand'
Upvotes: 2
Reputation: 27485
You can reference any environment variable, including Jenkins parameters, as any other variable in linux: ${VARNAME}
Upvotes: 4