5

I am trying to configure Jenkins in a Windows 7 environment to work with Git repository on Bitbucket, but when I try to do a build - I get the error below.

This is the Repository URL I am using:

https://<MY_ID>:<MY_PASSWORD>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git

Not sure if I need to generate keys for Jenkins-Bitbucket, if yes, can anyone please provide detailed instructions on how to do that for Windows?

Started by user anonymous
Building in workspace C:\Users\<MY_NAME>\.jenkins\workspace\<MY_PROJECT>
Fetching changes from the remote Git repository
Fetching upstream changes from https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git
FATAL: Failed to fetch from https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git
hudson.plugins.git.GitException: Failed to fetch from https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:612)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:836)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:861)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1414)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:652)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:561)
    at hudson.model.Run.execute(Run.java:1678)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git +refs/heads/*:refs/remotes/<MY_ID>/*" returned status code 128:
stdout: 
stderr: fatal: Authentication failed for 'https://<MY_ID>@bitbucket.org/<MY_ID>/<MY_REPO_NAME>.git/'

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1098)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:984)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:68)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:217)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.fetch(CliGitAPIImpl.java:223)
    at hudson.plugins.git.GitAPI.fetch(GitAPI.java:229)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:610)
    ... 10 more
user1004462
  • 133
  • 1
  • 1
  • 8

2 Answers2

8

OK, here is what worked for me, but first, my set-up was as follows:

  1. Windows 7
  2. Jenkins (with Git plugin)
  3. Git
  4. Account on Bitbucket

I started by following this tutorial. It works on Windows, all you have to do is double-click "Git Bash" in "C:\Program Files (x86)\Git" and follow the instruction to generate ssh keys. I only had to do Step 2 and Step 3.

NOTE: I generated keys without a passphrase! This was the only way I could get it to work...

Then, open the public key file "id_rsa.pub" that was generated in "C:\Users\YOUR_WINDOWS_USER_NAME\.ssh" with a text editor and copy the content. Once you have the public key, you need to register it with Bitbucket, go to "Manage Account" -> "SSH Keys" -> "Add Key". Paste your public key and save.

To test the keys, I ran this command:

$ ssh -T git@bitbucket.org
logged in as <USER_ID>.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

Now you need to register your private key with Jenkins: go to "Credentials" -> "Global credentials" -> "Add Credentials", enter your User Name, Description (optional), select "From a file on Jenkins master" and enter C:\Users\YOUR_WINDOWS_USER_NAME\.ssh\id_rsa.

Last step is to configure Jenkins job. Under "Source Code Management", select "Git", under "Repository URL", enter:

git@bitbucket.org:<USER_ID>/<REPO_NAME>.git

Under "Credentials", select credential that you've just created.

NOTE: make sure that when you go to "Manage Jenkins" -> "Configure System" -> "Git", "Path to Git executable" is set to something like "C:\Program Files (x86)\Git\cmd\git.exe".

Following these steps I was able to pull down my code from the repository.

user1004462
  • 133
  • 1
  • 1
  • 8
  • +1. That follows my answer and uses the links I mentioned. I also like to not have passphrase at first, at least to make it work. If you have a passphrase protected private ssh key, you need an ssh-agent: http://stackoverflow.com/a/14913230/6309 – VonC Dec 19 '13 at 06:17
0

Not sure if I need to generate keys for Jenkins-Bitbucket

Keys? As in "ssh keys"? Certainly not if you are using an https url (as in this question). Login and password should be enough.

Double check your login/password and url: it is case sensitive.

Make sure your password don't have any special character (that you would need to percent-encode, as in this case).


For using an ssh url, you can follow "Use the SSH protocol with Bitbucket" (after setting up ssh).
Make sure to modify the url of your git repo in your Jenkins job config to:

git@bitbucket.org:accountname/reponame.git
# or
ssh://git@bitbucket.org/accountname/reponame.git

But, make sure Jenkins runs as the user where the ssh keys are stored: see "Jenkins finds cannot find ssh key" and this BitBucket thread. (Check also your firewall)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Exactly as in "ssh", in which case the URL would change to "ssh" as well. Somehow the "https" does not work from Jenkins, while my EGit plugin in Eclipse is configured and works fine over "https" (un-encoded). That's why I was looking for step-by-step instructions to configure this over "ssh". – user1004462 Dec 17 '13 at 12:50
  • @user1004462 I understand, but your question explicitly states that you are using an https url... – VonC Dec 17 '13 at 12:53
  • @user1004462 I have edited my answer to address the ssh aspect of your question. – VonC Dec 17 '13 at 13:03