7

I am using RedHat Linux

  1. I have created a repository in BitBucket say Demo and I have some HTML code into that.
  2. I have installed Jenkins on my system.

What I am trying to do is clone the BitBucket repository with Jenkins so that I will be able to build the project.

Steps what I am following is

  1. Creating a new Job In Jenkins.
  2. Giving a description of the project
  3. In the Source Code Management tab selecting git and Jenkins ask for repository URL, and I am giving this URL. enter image description here

but Jenkins throwing an error saying:

Failed to connect to repository : Error performing command: git ls-remote -h git clone https://UserName@bitbucket.org/UserName/java-script.git HEAD

I spent around 3 days and could not configure this instead learned a lot about Jenkins. I have also tried the BitBucket plug-in for Jenkins that also was not working.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
Varun
  • 4,342
  • 19
  • 84
  • 119
  • 1
    possible duplicate of [How to configure jenkins with bitbucket](http://stackoverflow.com/questions/31074395/how-to-configure-jenkins-with-bitbucket) – nwinkler Jun 29 '15 at 08:59

3 Answers3

8

For Jenkins 1.5 or greater( till 1.6)

The error you are getting because in the global configuration of Jenkins, the git path is not correct/or not inserted.

That's why Jenkins is unable to run the git command.

Please go to Manage Jenkins-> Configure System Settings. Check for git section and add correct path.

enter image description here Its already seems that you have removed the Git Clone from the URL provided by Bitbucket.

Update:

For Jenkins 2.0 or above

You can find this setting under Global tool configuration.

Abhijeet Kamble
  • 3,131
  • 2
  • 30
  • 36
  • correct path. in the sense the Bitbucket path which I have shown in the above scree – Varun Jun 25 '15 at 09:42
  • no not the bitbucket path. i am talking about the path where git is installed on your system. for ex. my machine is linux(centos 6.5) and in my case git is installed at /usr/local/bin/git. or if its windows it might be C:\Program Files\Git\bin\git.exe – Abhijeet Kamble Jun 25 '15 at 09:49
  • the bitbucket path is correct. https://DrunkenCooder@bitbucket.org/DrunkenCooder/java-script.git – Abhijeet Kamble Jun 25 '15 at 09:50
  • Sorry bro i have not installed git in my system. I'll just do that. but, why do we need git since we are pulling the code from Bitbucket ? – Varun Jun 25 '15 at 10:23
  • 1
    Jenkins doesn't comes with GIT,So we have to install GIT and have to tell Jenkins about GIT path so that Jenkins can run GIT commands at backend. Hope this has answered your question. – Abhijeet Kamble Jun 25 '15 at 10:28
  • After installing git and after giving the path I am getting this error – Varun Jun 25 '15 at 10:50
  • Could not init /tmp/hudson4551896643487321839tmp – Varun Jun 25 '15 at 10:56
  • as u have mention I have specified the git executable path /usr/bin/git . now I have getting this error "Failed to connect to repository : Command "/usr/bin/git config --local credential.helper store --file=/tmp/git3516666924035828487.credentials" returned status code 129: stdout: stderr: error: unknown option `local' usage: git config [options] Config file location --global use global config file --system use system config file -f, --file use given config file – Varun Jun 26 '15 at 11:08
  • instead of `Configure System Settings` in Jenkins 2.27 it's called `Global Tool Configuration` – vaskort Oct 27 '16 at 13:42
  • @BillK Yes you are right, Now from Jenkins 2 its defined under Global Tool Configuration. – Abhijeet Kamble Oct 28 '16 at 16:56
0

Remove the "git clone" keywords and it should work :)

Jenkins only need the http URL:

https://UserName@bitbucket.org/UserName/java-script.git

Ajay2707
  • 5,690
  • 6
  • 40
  • 58
Bruno Lavit
  • 10,184
  • 2
  • 32
  • 38
  • When I am giving the whole URL git clone https://DrunkenCooder@bitbucket.org/DrunkenCooder/java-script.git , it throws this "Failed to connect to repository : Error performing command: git ls-remote -h git clone https://DrunkenCooder@bitbucket.org/DrunkenCooder/java-script.git HEAD " – Varun Jun 25 '15 at 09:26
  • When I am giving only URL https://DrunkenCooder@bitbucket.org/DrunkenCooder/java-script.git , it throws this " Failed to connect to repository : Error performing command: git ls-remote -h https://DrunkenCooder@bitbucket.org/DrunkenCooder/java-script.git HEAD" – Varun Jun 25 '15 at 09:27
  • On your Jenkins server, are you able to run the git clone http//... command? – Bruno Lavit Jun 25 '15 at 09:31
-1

This is because private key is not establishing to GIT through Jenkins.

So create credentials:

  1. go to Jenkin Configure==>Source Code Management==>Add==>Jenkins;
  2. select Domain as global;
  3. select Kind 'SSH username with password';
  4. Copy the user name from id_rsa.pub file and paste it in username field;
  5. Copy the private key from id_rsa file and paste it in 'Private Key==> Enter directly'

It should work, try it.

arghtype
  • 4,376
  • 11
  • 45
  • 60