I have a Jenkins job which runs a shell script. It works perfectly when the script is placed directly in the Build command field. But if I put the script in a .sh file and then call that fine from the Build command field:
sh $sh_dir/deploy.sh $repo_dir $name $ref $env $site_dir
$sh_dir
is an env variable and the rest are job parameters. It doesn't work, it fails on the first command which is simply
cd $1/$2
Again, this works perfectly when put directly in the command field, but not when in the .sh file. The output from the .sh file job is:
Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/deploy
[deploy] $ /bin/sh -xe /tmp/hudson6229756058999358596.sh
+ /var/lib/jenkins/scripts/deploy.sh /home/repos magento master live /home/sites
cd: 1: can't cd to /home/repos/magento
Yes the directory does exist and yes it is owned by jenkins
.
I'm going out of my mind trying to figure this out.
Edit: result of deploy.sh with -x
:
Started by user anonymous
Building in workspace /var/lib/jenkins/workspace/deploy
[deploy] $ /bin/sh -xe /tmp/hudson3304816709711757032.sh
+ sh -x /var/lib/jenkins/scripts/deploy.sh /home/repos magento develop staging /home/sites
+ cd /home/repos/magento
cd: 1: can't cd to /home/repos/magento
The discussion in the comments was taken to chat.
The problem was eventually discovered to be Windows line endings (CRLF) causing confusion. For example, the directory /home/repos/magento\r
with a CR at the end really doesn't exist. There are Windows CIF shared folders lurking around. The solution will involve working out how to convert the scripts to native Unix (LF only) line endings.
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