3

since the last update of jenkins and the git plugin the http auth via .netrc does not work anymore. I really checked many many threads about this issue.

I tried to use also the variant http://user:pass@url.tld/repo.git which works. But internally we are providing a vm which contains all needed jobs for development. Before the update we just edited the .netrc file in jenkins home folder and jenkins works perfectly.

I also tried already via console git clone http://url.tld/repo.git which works fine, even on the jenkins user.

Here are some details:

  • Jenkins: v1.536
  • GIT Plugin: v2.0
  • GIT client plugin: v1.4.5
  • GIT: 1.8.4.GIT
  • Centos: 6.4
  • Java: 1.6.0

The .netrc

machine url
        login user
        password pass

Here the error of jenkins in the configuration mask: Failed to connect to repository : Failed to connect to http:// ....git (status = 401)

Would be fine if someone has an idea.

maTu
  • 289
  • 1
  • 3
  • 10

5 Answers5

3

With the Git client Plugin 1.4.5 you will need to use a different format for your .netrc file. The Git client plugin requires the information for a host in the .netrc file all in one line. So changing this

machine hostname
    login user
    password secret

to this

machine hostname login user password secret

should make it work again.

Certainly not the best implementation on the plugins side, but unfortunately currently the case. Note that there must only be a single space between the words in the line. Avoid trailing white space, too.

In addition to that, due to a bug, the first such line in the file will be taken, whether the host name matches or not. So if you need to have multiple hosts in your .netrc file, that will not work. Or rather only with the first one listed. No known workaround.

Note, that if you use a _netrc file under windows, chances are that it will not be found, as the git client plugin (in version 1.4.6) doesn't search it in the Jenkins user's home directory. A work around is to have a .netrc file under windows, too.

Florian
  • 489
  • 4
  • 13
  • Interesting. +1. I have reference your workaround in my answer for more visibility. – VonC Nov 20 '13 at 20:52
  • For those who don't want to downgrade but still need multiple hosts in the file and are fine with compiling a fixed version themselves until the official plugin is fixed, there is a [patch available on GitHub](https://github.com/fzs/git-client-plugin/tree/netrc-parsing). – Florian Nov 21 '13 at 19:19
  • In my case adding the one-line file `_netrc` (for Git) and `.netrc` (for Git Client) to `C:\Users\` folder helped. Also make sure the `Path to Git executable` in your Jenkins is set to `cmd\git.exe`, not `bin\git.exe`. – mgr32 Dec 13 '13 at 14:10
2

This issue was initially detected with the Git client plugin 1.4.3, and supposed to be fixed in 1.4.4 by Nicolas De Loof:
See issue 20175.

Try and downgrade the git client plugin to 1.4.4.
If 1.4.5 introduced a regression, then re-open issue 20175.

Florian's answer (upvoted) suggest a possible cause for git client plugin to 1.4.5, regarding the .netrc format.

machine hostname login user password secret

(one line only, instead of several lines)

Florian insists in the comments about the presence of some bugs:

  • If you have multiple hosts defined in the .netrc file, the first one will be taken, no matter if it is the correct one or not.
  • Also, under windows a _netrc file will most probably not be found as it is not searched in the Jenkins user's home directory.
    It (a _netrc file) isn't read by the git client plugin (right now, November 2013) to retrieve the credentials.
    It works correctly with .netrc, but not with _netrc, no matter if Windows or Unix.
    So I would suggest to have an identical .netrc file in the home directory under Windows, in addition to the _netrc, until this bug (JENKINS-20688) is fixed.

He mentions the presence of a jenkinsci/git-client-plugin patch on GitHub.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This works not really for me. The version 1.4.4 also does not work properly. I tested with git-plugin 1.4 and git-client-plugin 1.0.7 this works now! – maTu Oct 26 '13 at 15:14
  • If you have multiple hosts defined in the .netrc file, the first one will be taken, no matter if it is the correct one or not. Also, under windows a _netrc file will most probably not be found as it is not searched in the Jenkins user's home directory. – Florian Nov 21 '13 at 19:07
  • @Florian that doesn't sound good... Isn't the `_netrc` always searched under `%HOME%`? – VonC Nov 21 '13 at 19:08
  • It is by curl, AFAIK, but it isn't by the git client plugin (right now) which reads and parses it to retrieve the credentials. It works correctly with .netrc, but not with _netrc, no matter if Windows or Unix. So I would suggest to have an identical .netrc file in the home directory under Windows, in addition to the _netrc, until this bug is fixed. ([JENKINS-20688](http://issues.jenkins-ci.org/browse/JENKINS-20688)) – Florian Nov 21 '13 at 19:26
  • @Florian Ok, I have added your comments to the answer for more visibility. – VonC Nov 21 '13 at 19:29
1

Here to add for all others:

Download link for the downgrade files:

Git Client Plugin 1.0.7: http://mirrors.jenkins-ci.org/plugins/git-client/1.0.7/git-client.hpi

Git Plugin 1.4.0: http://mirrors.jenkins-ci.org/plugins/git/1.4.0/git.hpi

maTu
  • 289
  • 1
  • 3
  • 10
0

I had to downgrade the Git Client Plugin to 1.3.0 version to make it work again.

Here is the download link : http://mirrors.jenkins-ci.org/plugins/git-client/1.3.0/git-client.hpi

0

FWIW, for me the workaround was mentioned on issue 21015

Shai Berger
  • 2,963
  • 1
  • 20
  • 14