Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting Bitbucket and Jenkins

Alexander Spetko
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 7, 2012

Hi,

I am using git (at bitbucket) as a source code repository. Since I could not make the git jenkins plugin run, I have set up a shell skript (on Linux Ubuntu) that checks out my source code from git.

At the moment, I am running this job every day, but I was wondering, if it is possible to connect the git repository to the jenkins task, as some kind of hookup.

So every time, I change something on the source files, the build will be triggered to run.

This is interesting for older projects, where are not so many changes and therefore I don't need to run a build on a daily base.

Thanks in advance and please excuse my english. It 's not my mother language.

Best regards,

Alexander Spetko

29 comments

Comment

Log in or Sign up to comment
Thomas Einwaller October 21, 2012

You can easily configure jenkins to check the bitbucket git repository every 10 minutes and have a built triggered if something changes in the repository.

  1. install the git plugin in jenkins
  2. configure the bitbucket repository url
  3. add a deployment key for the user jenkins is running under in the bitbucket repository configuration
  4. set a cron schedule for checking the repository
Alexander Spetko
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 21, 2012

Thank you for your answer but when you read my question carefully, you will see that my second sentence is:

"Since I could not make the git jenkins plugin run, ...."

> 1. install the git plugin in jenkins,

is therefore not really a solution for my problem.

Thanks anyway.

Alexander

Thomas Einwaller October 21, 2012

I think you should try to get the git plugin running ... that should be very easy - what is the problem with the plugin?

Claudio De Pace November 6, 2012

Hi,

May I know how to "add a deployment key for the user jenkins is running under in the bitbucket repository configuration"?

thanks

Thomas Einwaller November 6, 2012

You need to create a ssh key by running ssh-keygen, this creates a id_rsa and a id_rsa.pub file in the directory ~/.ssh

then you have to add the content of the id_rsa.pub file to the bitbucket repository und deployment keys

Claudio De Pace November 6, 2012

Hi Thomas,

so..what I've done:

ssh-keygen -t rsa
 pbcopy < /Users/jenkins/.ssh/id_rsa.pub 

and I added this SSH key to my BitBucket profile.

but in the configuration area,when I use /https://myname@bitbucket.org/myname/myproject.git

I get the error: Failed to connect to repository : Error performing command: git ls-remote -h https://...</span<>>

Claudio De Pace November 6, 2012

shall I use

ssh://git@bitbucket.org

Thomas Einwaller November 6, 2012

use the url that is shown on the bitbucket repository front page, something like

git@bitbucket.org:blindjustis/public.git

Claudio De Pace November 6, 2012

OK. I'm getting close. The error message was not clear. I've fixed the git executable directory path and now the new message is

Failed to connect to repository : Command "/usr/local/git/bin/git ls-remote -h git@bitbucket.org:myname/myproject.git HEAD" returned status code 128: stdout: stderr: Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists

Like • 3 people like this
dinesh_arumugam
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 17, 2018

Hi Claudio,

when connecting to Bitbucket from jenkins repo
the actual url given by bit bucket is "ssh://git@bitbucket.org:dinesh_arumugam/vsci.git"
the above url will give the beow error:

Failed to connect to repository : Command "git ls-remote -h ssh://git@bitbucket.org:your_name/vsci.git HEAD" returned status code 128:
stdout:
stderr: ssh: Could not resolve hostname bitbucket.org:dinesh_arumugam: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

To solve the above error just change the bitbucket repo link to
ssh://git@bitbucket.org/your_name/vsci.git
by just replacing the ':' in to slash '/' before your name 

to configure it in jenkins jobs in the GIT repo option.

jenkins-config-1.png

then try to run the run the below command in your terminal
"git ls-remote -h ssh://git@bitbucket.org/your_name/vsci.git HEAD"

just replace the ':' into a slash '/'

once the command is run you will get it working in the jenkins tool
and your ssh will be generated.

jenkins-config-edited.png

regards,

Dinesh Arumugam

Kanthi Saranya Remella
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 6, 2018

Hi,

Im facing similar issue. But when I ran the "git ls-remote -h ssh://git@bitbucket.org/your_name/vsci.git HEAD" command, it doesn't return anything. No error, nothing.. Can you pls help.

Like • KosmosasRaketa likes this
Thomas Einwaller November 6, 2012

Host key verification failed

you need to make sure that the host key is in the allowed hosts. Simple do this by running the command

ssh git@bitbucket.org

and answer the question that asks to add the host with yes

Claudio De Pace November 6, 2012

Done. Back to the other error

Failed to connect to repository : Command "/usr/local/git/bin/git ls-remote -h git@bitbucket.org:myname/myproject.git HEAD" returned status code 128:
stdout:
stderr: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I really don't know how to fix it....

Claudio De Pace November 6, 2012

Ok I've done it

Jenkins:~ vejenkins$ ssh git@bitbucket.org

PTY allocation request failed on channel 0

conq: logged in as myname

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

Connection to bitbucket.org closed.

but it keeps on failing. In the URL config are I've provided it as ssh://git@bitbucket.org:myname/myproject.git

but the error is

stderr: ssh: Could not resolve hostname bitbucket.org:myname: nodename nor servname provided, or not known

Thomas Einwaller November 6, 2012

use git@bitbucket.org:myname/myproject.git as repository URL (without the ssh://)

Claudio De Pace November 6, 2012

yes it's working

Jenkins:~ vejenkins$ git clone git@bitbucket.org:myname/myproject.git

Cloning into 'myproject'...

remote: Counting objects: 5494, done.

remote: Compressing objects: 100% (4113/4113), done.

Receiving objects: 19% (1071/5494), 13.12 MiB | 529 KiB/s

also if I run:

/usr/local/git/bin/git ls-remote -h git@bitbucket.org:myname/myproject.git HEAD

it doesn't give any error message. It looks like Jenkings cannot run the command


Thomas Einwaller November 6, 2012

can you call

git clone git@bitbucket.org:myname/myproject.git

from the command line?

Thomas Einwaller November 6, 2012

have you tried restarting jenkins after adding the host do the authorized hosts?

is the jenkins running under the same user?

Claudio De Pace November 6, 2012

Yes I have done but still error. I think the problem are in the permission for git. In the error log the command which is failing is

/usr/local/git/bin/git clone --progress -o origin git@bitbucket.org:myname/myproject.git/Users/Shared/Jenkins/Home/jobs/MyProjectAdHocBuild/workspace

If I try to run it in the console I get this:

fatal: could not create work tree dir '/Users/Shared/Jenkins/Home/jobs/MyProjectAdHocBuild/workspace'.: Permission denied

so if I run it in SUDO mode it works.

How can I give to Jenkings the permission to run git in Admin mode?

Claudio De Pace November 6, 2012

I'm not sure THAT is the problem cos I've changed the permissions for the the project directory with

chmod 777 MyProjectAdHocBuild

but still....nothing....

at hudson.model.Executor.run(Executor.java:236)

Caused by: hudson.plugins.git.GitException: Command "/usr/local/git/bin/git clone --progress -o origin git@bitbucket.org:myname/myproject.git /Users/Shared/Jenkins/Home/jobs/myprojectAdHocBuild/workspace" returned status code 128:

stdout: Cloning into '/Users/Shared/Jenkins/Home/jobs/myprojectAdHocBuild/workspace'...

stderr: Host key verification failed.

fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

Like • Anderson Lorena likes this
Claudio De Pace November 6, 2012

found something here: https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

but how to find the user Jenkinds is running as? that tomcat6 referenced in the documentation is definitely wrong

Claudio De Pace November 6, 2012

I think the solution is here:

http://stackoverflow.com/questions/12097982/jenkins-finds-cannot-find-ssh-key

but I cannot find a way to implement all this command on the Macosx console....

It's definitely an user permission problem....any idea?

Thomas Einwaller November 6, 2012

what user do you use to start the tomcat jenkins is running in and how do you start tomcat?

running

ps axu | grep tomcat

should show what user the tomcat is running under

Claudio De Pace November 7, 2012

vejenkins is my user but it looks like the java process is running under another user called jenkins

Claudio De Pace November 7, 2012

This is the output:

Jenkins:~ vejenkins$ ps axu | grep "/jenkins"

vejenkins 11660 0.0 4.6 2918124 97096 ?? S 6:59pm 1:05.63 /usr/bin/java -jar /Users/vejenkins/Library/Caches/org.jenkins-ci.jenkins/jenkins.war

jenkins 9896 0.0 9.0 2939824 188552 ?? Ss 4:06pm 17:55.91 /usr/bin/java -jar /Applications/Jenkins/jenkins.war

vejenkins 11930 0.0 0.0 2432768 588 s000 S+ 10:28am 0:00.00 grep /jenkins

Jenkins:~ vejenkins$ ps axu | grep tomcat

vejenkins 11932 0.0 0.0 2432768 588 s000 S+ 10:28am 0:00.00 grep tomcat

Jenkins:~ vejenkins$

Claudio De Pace November 7, 2012

Maybe this can be useful:

MacMini:~ myuser$ cat /Library/LaunchDaemons/

com.logmein.logmeinserver.plist com.microsoft.office.licensing.helper.plist org.jenkins-ci.plist

MacMini:~ myuser$ cat /Library/LaunchDaemons/org.jenkins-ci.plist

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>StandardOutPath</key>

<string>/var/log/jenkins/jenkins.log</string>

<key>StandardErrorPath</key>

<string>/var/log/jenkins/jenkins.log</string>

<key>EnvironmentVariables</key>

<dict>

<key>JENKINS_HOME</key>

<string>/Users/Shared/Jenkins/Home</string>

</dict>

<key>GroupName</key>

<string>daemon</string>

<key>KeepAlive</key>

<true/>

<key>Label</key>

<string>org.jenkins-ci</string>

<key>ProgramArguments</key>

<array>

<string>/bin/bash</string>

<string>/Library/Application Support/Jenkins/jenkins-runner.sh</string>

</array>

<key>RunAtLoad</key>

<true/>

<key>UserName</key>

<string>jenkins</string>

<key>SessionCreate</key>

<true />

</dict>

</plist>

MacMini:~ myuser$

Claudio De Pace November 7, 2012

Ok maybe I found the solution here: http://colonelpanic.net/2011/06/jenkins-on-mac-os-x-git-w-ssh-public-key/

My problem now is different

Started by user anonymous

Building in workspace /Users/Shared/Jenkins/Home/jobs/myprojectAdHocBuild/workspace

Checkout:workspace / /Users/Shared/Jenkins/Home/jobs/myprojectAdHocBuild/workspace - hudson.remoting.LocalChannel@25f3b536

Using strategy: Default

Fetching changes from 1 remote Git repository

Fetching upstream changes from git@bitbucket.org:myuser/myproject.git

No candidate revisions

ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.

Archiving artifacts

Finished: FAILURE

At least I found how to check it out

TAGS
AUG Leaders

Atlassian Community Events