Configuring Jenkins with Bitbucket

本小妞迷上赌 提交于 2019-12-07 14:08:48

问题


I seem to have got stuck trying to link Jenkins (an EC2 AWS instance of Ubuntu) with Bitbucket.

Whenever I try to build my project (I've installed the git plugin on Jenkins) I get...

Building in workspace /var/lib/jenkins/jobs/Google adwords/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Google adwords/workspace - hudson.remoting.LocalChannel@2c473996
Using strategy: Default
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone git@bitbucket.org:DAVID99WORLD/assessme.git
hudson.plugins.git.GitException: Could not clone git@bitbucket.org:DAVID99WORLD/assessme.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:268)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1122)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1064)
    at hudson.FilePath.act(FilePath.java:842)
    at hudson.FilePath.act(FilePath.java:824)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1064)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1256)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:589)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:494)
    at hudson.model.Run.execute(Run.java:1502)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:477)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin git@bitbucket.org:DAVID99WORLD/assessme.git /var/lib/jenkins/jobs/Google adwords/workspace" returned status code 128:
stdout: Cloning into '/var/lib/jenkins/jobs/Google adwords/workspace'...

stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly

Fine - this looks like it's trying to go over ssh but can't find the keys. So I'm trying to generate the keys, under ~/.ssh I've got the files authorized_keys and known_hosts but according to the documentation here...

https://confluence.atlassian.com/display/BITBUCKET/How+to+install+a+public+key+on+your+bitbucket+account

I should have a file under ~/.ssh called id_rsa

I've been following the documentation...

https://confluence.atlassian.com/display/BITBUCKET/Using+the+SSH+protocol+with+bitbucket

But it looks almost either half finished or I'm missing the bit where the key gets put in the correct file.

Firstly - is my assumption correct this is an ssh issue? Secondly, if it is, does anyone know how to get the keys to match so Jenkins can make the pull and build?

EDIT : I assumed it was an ssh issue as the question Jenkins Build Using Git with Deploy Key was related, but I'm using bitbucket rather than github.


回答1:


You need to generate the key file to upload to your BitBucket account. From the user that is running Jenkins, do the following:

ssh-keygen -t rsa

Take the default for the key file location and leave the passphrase blank. You'll then have the ~/.ssh/id_rsa.pub file to upload to BitBucket.




回答2:


I was reading this post because I had the same problem and I have found something useful right now.

MY CONFIGURATION I have a slave building server (Win7-64 machine) where I have installed the standard Git (during installation I chose the third option: "Run Git and included Unix tools from the Window command prompt".) Jenkins is configured with Java Web Start.

I have noticed that if I execute from Git shell the command

ssh -vT git@bitbucket.org

I can authenticate with the server getting the message

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

BUT if i execute the same command from cmd, I get

Permission denied (publickey)

I'm not sure, but I think that Git plugin execute commands from the window shell and not with git shell (as I expected), so this could determine an authentication problem in the build.

In Git Plugin docs there is a little section called "Some windows fun" that suggest to copy the .ssh user's folder under Git folder (in my case C:\Program Files (x86)\Git).

After doing so, from windows shell I ran ssh -vT git@bitbucket.org and it worked (if it doesn't work, try to restart the shell or the entire machine). Then I ran the build from Jenkins and finally it worked.

I hope this could help.

Good luck.



来源:https://stackoverflow.com/questions/12096942/configuring-jenkins-with-bitbucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!