title: Jenkins can't access shell alias
body: <p>I have configured a Jenkins job to source a bash script that sources <em>another</em> bash script which adds an alias to the <code>.bashrc</code> of its user and sources the <code>.bashrc</code> itself, and then original script tries to use that alias (set by the second). However, it cannot seem to find the alias it has just created. I am not using any scripting plugins aside from using a "Send files or execute commands over SSH" build step to source the script.</p>
  
  <p>The job does this:</p>
  
  <pre><code>source ./test_script.sh
  </code></pre>
  
  <p><code>test_script.sh</code> looks like this:</p>
  
  <pre><code>echo "In test_script.sh"
  echo $USER
  echo $HOME
  source ./setup_env.sh
  echo "\nBack in test_script.sh"
  alias foo
  foo
  </code></pre>
  
  <p>And finally, <code>setup_env.sh</code> looks like this:</p>
  
  <pre><code>echo "\nIn setup_env.sh"
  echo "alias foo=\"echo foobar\"" &gt;&gt; $HOME/.bashrc
  source $HOME/.bashrc 2&gt;/dev/null
  cat $HOME/.bashrc
  </code></pre>
  
  <p>The output I receive from the Jenkins job looks like this:</p>
  
  <pre><code>In test_script.sh
  my_user
  /home/my_user
  \nIn setup_env.sh
  ...all of my bashrc...
  alias foo="echo foo"
  \nBack in test_script.sh
  alias foo='echo foo'
  ./test_script.sh: line 7: foo: command not found
  </code></pre>
  
  <p>I don't understand why this is happening, when I can happily run it myself on the command-line and watch it succeed. Why can't Jenkins use the new alias, when it can obviously find it (as demonstrated by the output of the <code>alias foo</code> command)?</p>