title: Jenkins unable to fetch repo - code 255 permission denied
body: <p>I'm trying to set up Jenkins to work with git webhooks. So far I have</p>
  
  <ul>
  <li>Jenkins running</li>
  <li>Created an ssh key pair under the <code>jenkins</code> user</li>
  <li>Added the key to git deploy keys</li>
  <li>Added the git plugin</li>
  <li>Configured the project to use git with the repo</li>
  <li>Set the branch to <code>*/develop</code> to only watch the dev branch</li>
  <li>Set the custom workspace directory to <code>/data/www/&lt;site&gt;</code></li>
  <li>Added the <code>ubunutu</code> group to the <code>jenkins</code> user (see below)</li>
  </ul>
  
  <p>And when trying to build the project, I get this error:</p>
  
  <pre><code>Started by user anonymous
  Building in workspace /data/www/&lt;site&gt;
   &gt; git rev-parse --is-inside-work-tree # timeout=10
  Fetching changes from the remote Git repository
   &gt; git config remote.jenkins.url git@github.com:&lt;repo_url&gt; # timeout=10
  ERROR: Error fetching remote repo 'jenkins'
  hudson.plugins.git.GitException: Failed to fetch from git@github.com:&lt;repo_url&gt;
      at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:735)
      at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:983)
      at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1016)
      at hudson.scm.SCM.checkout(SCM.java:485)
      at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
      at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:610)
      at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
      at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:532)
      at hudson.model.Run.execute(Run.java:1744)
      at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      at hudson.model.ResourceController.execute(ResourceController.java:98)
      at hudson.model.Executor.run(Executor.java:374)
  Caused by: hudson.plugins.git.GitException: Command "git config remote.jenkins.url git@github.com:&lt;repo_url&gt;" returned status code 255:
  stdout: 
  stderr: error: could not lock config file .git/config: Permission denied
  
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1591)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1567)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1563)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1249)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1261)
      at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.setRemoteUrl(CliGitAPIImpl.java:961)
      at hudson.plugins.git.GitAPI.setRemoteUrl(GitAPI.java:160)
      at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:723)
      ... 11 more
  ERROR: Error fetching remote repo 'jenkins'
  </code></pre>
  
  <p>The repo has already been pulled by a different user (in this case, <code>ubuntu:ubuntu</code>) in the <code>/data/www/&lt;site&gt;</code> directory, so initially I thought adding the <code>ubunutu</code> group to <code>jenkins</code> would fix the problem, but no luck. I've also tried logging in as the <code>jenkins</code> user and pulling the repo, which I can do successfully.</p>
  
  <p>I've tried googling everything I can think of, but most searches point to people who are having key problems, rather than config file permission problems. At this point I'm out of ideas.</p>
  
  <p>Edit:</p>
  
  <p><code>ls -la</code> in the <code>.git</code> dir:</p>
  
  <pre><code>drwxrwxr-x   2 ubuntu  ubuntu   4096 Mar  5 12:13 branches
  -rw-rw-r--   1 ubuntu  ubuntu     15 Mar  5 18:09 COMMIT_EDITMSG
  -rw-rw-r--   1 jenkins jenkins   318 Jun  1 14:55 config
  -rw-rw-r--   1 ubuntu  ubuntu     73 Mar  5 12:13 description
  -rw-rw-r--   1 ubuntu  ubuntu     88 May 29 12:50 FETCH_HEAD
  -rw-rw-r--   1 ubuntu  ubuntu     24 May 28 13:21 HEAD
  drwxrwxr-x   2 ubuntu  ubuntu   4096 May 28 13:49 hooks
  -rw-rw-r--   1 ubuntu  ubuntu  36480 May 29 12:50 index
  drwxrwxr-x   2 ubuntu  ubuntu   4096 Mar  5 12:13 info
  drwxrwxr-x   3 ubuntu  ubuntu   4096 Mar  5 12:13 logs
  drwxrwxr-x 260 ubuntu  ubuntu   4096 Apr 10 10:40 objects
  -rw-rw-r--   1 jenkins jenkins    41 May 29 11:53 ORIG_HEAD
  -rw-rw-r--   1 ubuntu  ubuntu    179 Mar  5 12:13 packed-refs
  drwxrwxr-x   5 ubuntu  ubuntu   4096 Mar  5 12:13 refs
  </code></pre>
  
  <p><code>ls -la</code> from the parent dir (it's a Laravel 5 app):</p>
  
  <pre><code>drwxrwxr-x 13 ubuntu   ubuntu    4096 Apr  3 11:07 app
  -rwxrwxr-x  1 ubuntu   ubuntu    2452 Mar  5 12:13 artisan
  drwxrwxr-x  2 ubuntu   ubuntu    4096 Mar 11 08:18 bootstrap
  -rwxrwxr-x  1 ubuntu   ubuntu    1094 Mar 11 08:16 composer.json
  -rw-rw-r--  1 ubuntu   ubuntu   79004 Mar 11 08:17 composer.lock
  -rwxrwxr-x  1 ubuntu   ubuntu     146 Mar  5 12:13 CONTRIBUTING.md
  drwxrwxr-x  8 ubuntu   ubuntu    4096 May  6 09:45 frontend
  drwxrwxr-x  8 ubuntu   ubuntu    4096 Jun  1 14:56 .git
  -rwxrwxr-x  1 ubuntu   ubuntu      12 Mar  5 12:13 .gitattributes
  -rwxrwxr-x  1 ubuntu   ubuntu     160 Mar  5 12:13 .gitignore
  -rwxrwxr-x  1 ubuntu   ubuntu     567 Mar  5 12:13 phpunit.xml
  drwxrwxr-x  7 www-data www-data  4096 Mar  5 17:13 public
  -rwxrwxr-x  1 ubuntu   ubuntu    2051 Mar  5 12:13 readme.md
  -rwxrwxr-x  1 ubuntu   ubuntu     519 Mar  5 12:13 server.php
  drwxrwxr-x 29 ubuntu   ubuntu    4096 Mar 11 08:18 vendor
  </code></pre>
  
  <p>Groups:</p>
  
  <pre><code>$ cat /etc/group | grep jenkins
  ubuntu:x:1000:jenkins
  jenkins:x:113:
  
  $ cat /etc/group | grep ubuntu
  adm:x:4:syslog,ubuntu
  dialout:x:20:ubuntu
  cdrom:x:24:ubuntu
  floppy:x:25:ubuntu
  sudo:x:27:ubuntu
  audio:x:29:ubuntu
  dip:x:30:ubuntu
  video:x:44:ubuntu
  plugdev:x:46:ubuntu
  netdev:x:102:ubuntu
  ubuntu:x:1000:jenkins
  </code></pre>