用git设置jenkins

时间:2014-10-12 06:27:22

标签: git jenkins tomcat7

我试图用Git设置jekins。当我尝试运行它给我的工作时

FATAL: Failed to fetch from git@bitbucket.org:xyzlk/xyzlk-services.git
hudson.plugins.git.GitException: Failed to fetch from git@bitbucket.org:xyzlk/xyzlk-services.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:647)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:889)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:914)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1253)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:622)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:528)
    at hudson.model.Run.execute(Run.java:1745)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:89)
    at hudson.model.Executor.run(Executor.java:240)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress git@bitbucket.org:xyzlk/xyzlk-services.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Permission denied (publickey).
fatal: Could not read from remote repository.

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

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1437)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1225)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:87)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:282)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:645)
    ... 10 more

我已将具有访问存储库权限的用户组分配给tomcat7。仍然没有运气。

我的jenkins配置我添加了

git@bitbucket.org:xyzlk / xyzlk-services.git作为repo,Kind为具有私钥的SSH用户名。有权访问repo并直接输入密钥的用户的用户名。仍然没有运气:(

enter image description here

enter image description here

权限

drwxr-xr-x  10 root root  4096 Oct 15  2013 usr
drwxr-xr-x 138 root root  4096 Oct 10 09:46 share

drwxr-xr-x   7 tomcat7 root  4096 Oct 13 08:23 tomcat7

在tomcat里面

drwxr-xr-x   2 tomcat7 tomcat7 4096 Oct 13 05:31 .ssh

里面.ssh

drwxr-xr-x 2 tomcat7 tomcat7 4096 Oct 13 05:31 .
drwxr-xr-x 7 tomcat7 root    4096 Oct 13 08:23 ..
-rwxr-xr-x 1 tomcat7 tomcat7 1679 Oct 13 05:25 id_rsa
-rwxr-xr-x 1 tomcat7 tomcat7  406 Oct 13 05:25 id_rsa.pub
-rwxr-xr-x 1 tomcat7 tomcat7 1326 Oct 13 05:29 known_hosts

1 个答案:

答案 0 :(得分:1)

你需要检查Jenkins执行作业时HOME是什么(另一种说法是检查Jenkins执行作业的帐户)。

根据环境变量HOME,Jenkins将在$HOME/.ssh (Unix)%HOME%\.ssh(Windows)

中查找公共/私有ssh密钥

您可以使用正确的用户在命令行ssh git@bitbucket.org中执行此操作 (我确认you must use 'git' here,而不是用户名)
但是你需要确保Jenkins在运行时使用相同的帐户。