Connecting Bitbucket and Jenkins

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

28 answers

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.

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

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

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

Hi,

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

thanks

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

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<>>

shall I use

ssh://git@bitbucket.org

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

git@bitbucket.org:blindjustis/public.git

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

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

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.

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

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....

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

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

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


can you call

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

from the command line?

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

is the jenkins running under the same user?

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?

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

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?

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

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

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$

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$

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Oct 08, 2018 in Teamwork

If you could delete any meeting from your calendar, which one would it be?

Let’s face it: most of us have too many meetings on our calendars. And few things are a bigger waste of time than recurring meetings that no longer provide any value to attendees (or the busines...

347 views 11 9
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you