-
Bug
-
Resolution: Fixed
-
Major
-
None
When configuring a Git URL with credentials, like "http(s)://user:password@server/path/to/repo.git", and explicitly selecting a single branch to build, the polling fails with 401 error:
Here is the stacktrace from scm-polling.log:
hudson.util.IOException2: Failed to connect to http://user@localhost:8888/git/xxx.git (status = 401)
at hudson.plugins.git.GitSCM.compareRemoteRevisionWith(GitSCM.java:458)
at hudson.scm.SCM._compareRemoteRevisionWith(SCM.java:356)
at hudson.scm.SCM.poll(SCM.java:373)
at hudson.model.AbstractProject._poll(AbstractProject.java:1415)
at hudson.model.AbstractProject.poll(AbstractProject.java:1335)
at hudson.triggers.SCMTrigger$Runner.runPolling(SCMTrigger.java:420)
at hudson.triggers.SCMTrigger$Runner.run(SCMTrigger.java:449)
at hudson.util.SequentialExecutionQueue$QueueEntry.run(SequentialExecutionQueue.java:118)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: hudson.plugins.git.GitException: Failed to connect to http://user@localhost:8888/git/xxx.git (status = 401)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getURLWithCrendentials(CliGitAPIImpl.java:1437)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getURLWithCrendentials(CliGitAPIImpl.java:1379)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getHeadRev(CliGitAPIImpl.java:1294)
at hudson.plugins.git.GitSCM.compareRemoteRevisionWithImpl(GitSCM.java:488)
at hudson.plugins.git.GitSCM.compareRemoteRevisionWith(GitSCM.java:456)
... 13 more
The problem is that the "fast remote polling" discards the in-URL password ("URIish.toString()"):
https://github.com/jenkinsci/git-plugin/blob/f6d42c4e7edb102d3330af5ca66a7f5809d1a48e/src/main/java/hudson/plugins/git/GitSCM.java#L488
I've verified that calling "toPrivateString()" there is enough to fix the bug. That said, it might be better/cleaner to extend the GitClient API with a "getHeadRev(URIish, String)", just like there is a "fetch(URIish, List<RefSpec>)" method for instance, and make the call to "toPrivateString" a bit deeper, where the password is actually required.