Using a Variable in Execute Shell that has a . in it

52 views
Skip to first unread message

Eric Fetzer

unread,
Feb 8, 2019, 12:25:17 PM2/8/19
to Jenkins Users
So it works fine to use a variable like build.dir as a parameter in a build trigger.  I'm finding, however, that when I add it to a "execute shell" command, it gets cut off at the ".".  For example:

Execute Shell:

Command:  ls -l $deploy.dir

This tries to ls -l on .dir because $deploy is unset.  I would very much appreciate any help.  I tried escaping the "." but that didn't work.  I tried putting quotes around the variable, no help.  Any help would be greatly appreciated!

Thanks,
Eric

Viacheslav Dubrovskyi

unread,
Feb 8, 2019, 12:42:31 PM2/8/19
to jenkins...@googlegroups.com

Hi Eric

Is it work for you?

sh """

    ls -l ${deploy.dir}

"""

08.02.2019 19:25, Eric Fetzer пишет:
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/bcb946d6-f25e-4bb3-8fc1-469986804a31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
-- 
WBD,
Viacheslav Dubrovskyi

Eric Fetzer

unread,
Feb 8, 2019, 1:48:43 PM2/8/19
to Jenkins Users
Here's what I put in:

sh """

ls -l ${deploy.dir}

"""

Here's what I got:

ls -l ${deploy.dir}

: bad substitution

Arnaud bourree

unread,
Feb 8, 2019, 1:52:45 PM2/8/19
to jenkins...@googlegroups.com
${deploy.dir} means attribute "dir" of object "deploy".
How do you setup deploy object?

--

Eric Fetzer

unread,
Feb 8, 2019, 2:09:36 PM2/8/19
to Jenkins Users
deploy.dir is a string parameter at the top of the job:

Capture.JPG





On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Eric Fetzer

unread,
Feb 8, 2019, 2:11:25 PM2/8/19
to Jenkins Users
If I renamed it deployDir, just using $deployDir would work, but this is a child job where the variable is set in the parent and used in this job as well so there would be a lot to change to get that working.  I'd prefer to be able to just use deploy.dir.  Thanks!


On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Arnaud bourree

unread,
Feb 8, 2019, 2:12:33 PM2/8/19
to jenkins...@googlegroups.com
Do not use dot in parameter names, prefer camel case, kebab case or skeleton case

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Eric Fetzer

unread,
Feb 8, 2019, 2:19:30 PM2/8/19
to Jenkins Users
Are you saying that it's not possible to make this work?  The .'s are already in there.  I guess I could write an ant script and just use them inside there because they work fine as parameters to a script...


On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Arnaud bourree

unread,
Feb 8, 2019, 2:23:26 PM2/8/19
to jenkins...@googlegroups.com
try: ${params.get('deploy.dir')}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Arnaud bourree

unread,
Feb 8, 2019, 2:29:03 PM2/8/19
to jenkins...@googlegroups.com
or ${params['deploy.dir']}

Eric Fetzer

unread,
Feb 8, 2019, 2:55:53 PM2/8/19
to Jenkins Users
Nope:

/tmp/jenkins8691176514212713317.sh: line 2: ${params.get('deploy.dir')}: bad substitution


On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Eric Fetzer

unread,
Feb 8, 2019, 2:56:49 PM2/8/19
to Jenkins Users
That was the first, let me try the second.


On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Eric Fetzer

unread,
Feb 8, 2019, 2:59:13 PM2/8/19
to Jenkins Users
Second one is:

/tmp/jenkins7135875844305012846.sh: line 2: deploy.dir: syntax error: invalid arithmetic operator (error token is ".dir")

On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Slide

unread,
Feb 8, 2019, 3:23:09 PM2/8/19
to Jenkins User Mailing List
What about ${params.'deploy.dir'}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--

Eric Fetzer

unread,
Feb 8, 2019, 3:29:52 PM2/8/19
to Jenkins Users
Sorry, no again:

/tmp/jenkins6366597011192684630.sh: line 2: ${params.'deploy.dir'}: bad substitution

On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Eric Pyle

unread,
Feb 8, 2019, 3:46:59 PM2/8/19
to jenkins...@googlegroups.com
From Stack Overflow:

depdir=`env|grep "deploy\\.dir="|cut -d = -f 2`
echo "deploy.dir == $depdir"

-Eric
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

-- 
Eric Pyle
Siemens PLM Software
Lebanon, NH
+1 603-277-3060
eric...@siemens.com
http://www.siemens.com/plm

Eric Fetzer

unread,
Feb 8, 2019, 3:55:41 PM2/8/19
to Jenkins Users
That there is some crazy stuff Eric, but it worked, lol:

[OIS-Client] $ /bin/sh -xe /tmp/jenkins1618762877704683861.sh
++ grep 'deploy\.dir='
++ cut -d = -f 2
++ env
+ depdir=/deploy
+ echo 'deploy.dir == /deploy'
deploy.dir == /deploy

I can work that into this and avoid using an ant script or rewriting 15 different jobs, THANKS!!!

On Friday, February 8, 2019 at 10:25:17 AM UTC-7, Eric Fetzer wrote:

Baptiste Mathus

unread,
Feb 10, 2019, 7:59:06 AM2/10/19
to jenkins...@googlegroups.com
You seem to have found a workaround, and not 100% thiis is what you did, but if these are environment variables with dots in it, you should remove them.

It's unsupported by most if not all shells.

So, you might have *worked around* it, but it will most likely bite again :).

Cheers

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.

Benjamin Primrose

unread,
Feb 15, 2019, 3:58:38 PM2/15/19
to jenkins...@googlegroups.com

Periods aren’t valid characters for a shell variable name, I can’t set one to test this.  Try using “${deploy.dir}” (as in “ls ${deploy.dir}”).  If that doesn’t work extracting it from your environment with env | grep | cut is going to be the best you’ve got assuming you can’t give it a valid name.

--

Reply all
Reply to author
Forward
0 new messages