【问题标题】:Setting up jenkins with git使用 git 设置詹金斯
【发布时间】:2014-12-06 23:40:29
【问题描述】:

我正在尝试使用 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

我已将有权访问 repo 的用户组分配给 tomcat7。还是没有运气。

我已经添加了我的詹金斯配置

git@bitbucket.org:xyzlk/xyzlk-services.git 作为 repo 和 Kind 作为带有私钥的 SSH 用户名。有权访问repo并直接输入key的用户的用户名。还是没有运气:(

权限

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

【问题讨论】:

    标签: git jenkins tomcat7


    【解决方案1】:

    当 Jenkins 执行作业时,您需要检查 HOME 是什么(另一种说法是检查 Jenkins 在哪个帐户下执行作业)。

    根据环境变量 HOME,Jenkins 将在 $HOME/.ssh (Unix)%HOME%\.ssh (Windows) 中查找公共/私有 ssh 密钥

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

    【讨论】:

    • 非常感谢您的回复。我给出了有权访问存储库的用户的用户名,并直接在 jenkins 配置中输入了密钥。它仍然会寻找 $HOME/.ssh 吗?
    • @Dilantha 你是通过 Jenkins SSH 代理插件做到的吗? (wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin)
    • 是的。我已经安装了 Jenkins SSH 插件
    • @Dilantha 不是“ssh 插件”,而是“ssh agent 插件,仅当您的私钥受密码保护时才需要。我建议使用不带密码的私钥首先,并尝试让它发挥作用。
    • 它的 ssh 代理插件和私钥没有密码保护。我已经添加了一些我目前拥有的设置的屏幕截图。你能得到一个想法吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-22
    相关资源
    最近更新 更多