title: Jenkins shell script not working when in a .sh file
body: <p>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:</p>
  
  <pre><code>sh $sh_dir/deploy.sh $repo_dir $name $ref $env $site_dir
  </code></pre>
  
  <p><code>$sh_dir</code> is an env variable and the rest are job parameters. It doesn't work, it fails on the first command which is simply</p>
  
  <pre><code>cd $1/$2
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Yes the directory does exist and yes it is owned by <code>jenkins</code>.</p>
  
  <p>I'm going out of my mind trying to figure this out.</p>
  
  <p>Edit: result of deploy.sh with <code>-x</code>:</p>
  
  <pre><code>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
  </code></pre>