Jenkins unable to fetch repo - code 255 permission denied

17,117

Solution 1

This works pretty nice form me:

1 - Find the git config.lock file, inside the jenkins folder run:

find . -type f -name "config.lock"

2 - Delete the config.lock file founded.

Thats it!

Solution 2

Check the owner / permissions of the .git/config file in the jenkins workspace. It's probably still owned by the ubuntu user. Change the owner to the jenkins user.

Solution 3

Maybe you've already looked at it but I found a forum post where links were given to tickets. Go through them, you may find something.

Citing :

More relevent listed errors are :

  • .git\config.lock needs to be deleted
  • Need git-client-plugin version 1.6.2 at least
Share:
17,117

Related videos on Youtube

Samsquanch
Author by

Samsquanch

Updated on September 17, 2022

Comments

  • Samsquanch
    Samsquanch about 1 year

    I'm trying to set up Jenkins to work with git webhooks. So far I have

    • Jenkins running
    • Created an ssh key pair under the jenkins user
    • Added the key to git deploy keys
    • Added the git plugin
    • Configured the project to use git with the repo
    • Set the branch to */develop to only watch the dev branch
    • Set the custom workspace directory to /data/www/<site>
    • Added the ubunutu group to the jenkins user (see below)

    And when trying to build the project, I get this error:

    Started by user anonymous
    Building in workspace /data/www/<site>
     > git rev-parse --is-inside-work-tree # timeout=10
    Fetching changes from the remote Git repository
     > git config remote.jenkins.url [email protected]:<repo_url> # timeout=10
    ERROR: Error fetching remote repo 'jenkins'
    hudson.plugins.git.GitException: Failed to fetch from [email protected]:<repo_url>
        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 [email protected]:<repo_url>" 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'
    

    The repo has already been pulled by a different user (in this case, ubuntu:ubuntu) in the /data/www/<site> directory, so initially I thought adding the ubunutu group to jenkins would fix the problem, but no luck. I've also tried logging in as the jenkins user and pulling the repo, which I can do successfully.

    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.

    Edit:

    ls -la in the .git dir:

    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
    

    ls -la from the parent dir (it's a Laravel 5 app):

    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
    

    Groups:

    $ 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
    
  • Samsquanch
    Samsquanch over 8 years
    It is owned by the ubuntu user, but jenkins is in the ubunutu group which I assumed would be enough? And if it's not, why can I manually pull when logged in as the jenkins user?
  • Samsquanch
    Samsquanch over 8 years
    git-client-plugin is at 1.17.1. config.lock doesn't exist. The error references just config.
  • RPresle
    RPresle over 8 years
    Could you give us the result of ls -la in the .git directory and from its parent directory. And cat /etc/group | grep jenkins and cat /etc/group | grep ubuntu . I would like to be sure about permission.
  • Samsquanch
    Samsquanch over 8 years
    Added all this info to the question.
  • RPresle
    RPresle over 8 years
    Are you sure that Jenkins is running with jenkins user? Odd question I'm sorry, I can't find out why it's not going the right way. This command is clearly local, so it has no link with github and ssh key. I tried several thing and got almost similar error when I had no config file (error: could not lock config file .git/config: No such file or directory). The next operation done by Jenkins is Fetching upstream changes from <repo>. Some problems may appear there with unknown_host, but if you tried manually you must have accept the host... Check Jenkins user or try full right (just testing)
  • Samsquanch
    Samsquanch over 8 years
    I can confirm that it looks like it's using the jenkins user. I created a new item, and the files that item creates show jenkins:jenkins as the owner.
  • Samsquanch
    Samsquanch over 8 years
    At this point I'm not even sure I'm using Jenkins the way it's supposed to be used, but I'd still like to figure out what the issue is here.
  • RPresle
    RPresle over 8 years
    have you tried to clean the local repo? Maybe just by cleaning all the project directory and let Jenkins pull from scratch
  • RPresle
    RPresle over 8 years
    Have you found a solution?
  • javabrett
    javabrett over 8 years
    jenkins in the ubuntu group is OK, provided you have rebooted/restarted.
  • Emil B. Kjer
    Emil B. Kjer over 8 years
    I added the dir mkdir ~/.git and it fixed the error for me. Ref: groups.google.com/d/msg/git-users/pyv6ldFxUio/qV4pvE_z3zwJ