brian
brian

Reputation: 3

Remote shell in Jenkins seems to change my script when it runs

We are transitioning to Jenkins from using Unix build scripts. Things are moving along but I'm stuck when I try to copy and rename 2 'artifacts' on the build host.

My command in Remote shell is:

#!/usr/bin/ksh
cd /tmp
for f in "ns_a*Z"; do cp -p $f /ci/${f}_$BUILD_ID; done

When Jenkins runs it displays the console output as:

##################################################################################
##################################################################################
Last unsuccessful login: Tue May 19 21:18:38 2015 on ssh from mgt04.n.com
Last login: Fri May 22 18:47:50 2015 on /dev/pts/2 from ndev.n.com


*******************************************************************************
*  Welcome to AIX Version 5.3!                                                *
*                                                                             *
*******************************************************************************
#!/usr/bin/ksh

cd /tmp

echo $BUILD_ID

for f in "ns_a*Z"; do  cp -p $f /ci/${f}_$BUILD_ID; done

exit $?

b@dev02:/home/b> #!/usr/bin/ksh
b@dev02:/home/b>               
b@dev02:/home/b> cd /tmp
b@dev02:/tmp>              
b@dev02:/tmp> echo $BUILD _ID

b@dev02:/tmp>               
b@dev02:/tmp> for f in "ns _a*Z"; do  cp -p $f /c
b@dev02:/tmp> p -p $f /c                        <i/${f} _$B
b@dev02:/tmp> i/${f} _$BUILD _ID; done
cp: /ci/ns_a_3.1NS0.0-A-testb_bin.tar.Z_: not a directory.
b@dev02:/tmp>                                       
b@dev02:/tmp> 
b@dev02:/tmp> exit $?
#################################################################################
execute command exit status -->1
#################################################################################
Build step 'Remote Shell' marked build as failure

Finished: FAILURE

The output looks a little garbled but this is what it looks like on my screen. Of course if I run this as the b user on the host the script works fine.

A listing of /tmp looks like:

b@dev02:/tmp> ll
+ ls -al
total 36880
drwxr-xr-x    3 b      staff       256 May 22 14:20 .
drwxrwxrwx   11 bin    bin       12288 May 22 14:20 ..
drwxr-xr-x    3 b      staff       256 May 22 14:20 ns_a.pkg
drwxr-xr-x    3 b      staff    125256 May 22 14:20 ns_a_3.1NS0.0-A-testb_bin.tar.Z
drwxr-xr-x    3 b      staff    125388 May 22 14:20 ns_a_3.1NS0.0-A-testf_bin.tar.Z
b@dev02:/tmp>

Now that I'm writing this I see that the BUILD_ID is not making to the shell but I'm guessing I can find that later. For now it looks like somewhere the copy command is getting expanded to:

cp -p ns_a_3.1NS0.0-A-testb_bin.tar.Z ns_a_3.1NS0.0-A-testf_bin.tar.Z  /ci/ns_a_3.1NS0.0-A-testf_bin.tar.Z_

I'm using Jenkins 1.613 on Windows 7 and my build host is AIX 5.3.8.2.

I really don't consider this a complex script but I guess I will break it down into smaller bites and maybe I can get it to work then.

Thanks in advance if you have any ideas on where I'm going wrong.

Upvotes: 0

Views: 957

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295308

This is always wrong, as it executes only once -- making the for loop useless -- expanding the globs in that loop's arguments:

for f in "ns_a*Z"; do  cp -p $f /ci/${f}_$BUILD_ID; done

Instead, expand the glob before entering the loop (by leaving the glob expression unquoted), and quote all expansions within it:

for f in ns_a*Z; do cp -p "$f" /ci/"${f}_$BUILD_ID"; done

Upvotes: 1

Related Questions