title: How to use SSH id file from an ANT target called by Jenkins which uses Composer to clone library from GitLab?
body: <p>We're developing a few sites with common modules, and using GitLab to host the repositories.</p>
  
  <p>GitLab uses deploy keys to allow services like Jenkins to clone/checkout/pull the repository for automated builds and testing. We've got the public/private keys configured on the server running Jenkins, and the project successfully clones from GitLab.</p>
  
  <p>Where we're coming unstuck is the using an ANT to have the Jenkins build process run a Composer install and update the libraries used by the project.</p>
  
  <p>As we're developing the libraries along with the project(s), our Composer configuration is set to clone from the GitLab repositories. This works well on our development machines, as Composer is using the user's public/private key to connect into the GitLab repo.</p>
  
  <p>The problem is Jenkins - the "user" trying to clone the repo is Jenkins. I've tried creating a folder for <code>jenkins</code> under the home directory and generating a public/private key pair under the .ssh directory, and then added <code>/home/jenkins/.ssh/config</code>:</p>
  
  <pre><code>host gitlab.local
      HostName        gitlab.local
      IdentityFile    ~/.ssh/id_rsa
      User            git
  </code></pre>
  
  <p>Permissions are:</p>
  
  <pre><code>drwx------ 2 jenkins jenkins 4096 Mar 16 09:07 ./
  drwxr-xr-x 3 jenkins jenkins 4096 Mar 16 09:07 ../
  -rw------- 1 jenkins jenkins   84 Mar 16 09:07 config
  -rw------- 1 jenkins jenkins 1679 Mar 16 09:07 id_rsa
  -rw-r--r-- 1 jenkins jenkins  397 Mar 16 09:07 id_rsa.pub
  </code></pre>
  
  <p>The ANT target is pretty straightforward:</p>
  
  <pre><code>&lt;target name="composer-install" description="Download and install dependencies using Composer"&gt;
      &lt;exec executable="composer" failonerror="true"&gt;
          &lt;arg value="install"/&gt;
      &lt;/exec&gt;
  &lt;/target&gt;
  </code></pre>
  
  <p>And Composer is installed globally on the system.</p>
  
  <p>However, it doesn't appear that Jenkins is loading the SSH config from the directory I created, and it fails to authenticate when the ANT-trigger Composer tries to clone from GitLab.</p>
  
  <p>Is there a way to make this work?</p>
  
  <p><a href="https://help.fortrabbit.com/private-composer-repos" rel="nofollow noreferrer">One option</a> is to put the public/private key pair in the <code>composer.json</code> file - but then every developer will need these keys on their computers to do install/update on their PCs.</p>
  
  <p>Another option is to run Satis and have Composer get the packages from there - but this is not ideal, as the Satis library needs to be rebuilt and will delay the build process.</p>