Jenkins和Stash设置ssh密钥

时间:2012-11-27 16:57:53

标签: git ssh jenkins bitbucket-server

我在同一台服务器上设置了jenkins和stash。 Stash通过http工作得很好。为了让Jenkins连接到Stash,我创建了一个ssh(使用Jenkins用户,密钥存储在/var/lib/jenkins/.ssh/id_rsa.pub中)。正如指南所说,我已将此密钥添加到我的个人资料中,并在Administartion>服务器设置中启用了ssh。

在jenkins我安装了Git插件并在genarl配置中:

Global Config user.name Value

Global Config user.email Value

在项目配置中,我设置了以下字段:

存储库网址:ssh://git@10.10.2.40:7999 / AT / repository1.git

如果我运行该作业,则会出现以下错误:

Building in workspace /var/lib/jenkins/jobs/Test Job/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Test Job/workspace - hudson.remoting.LocalChannel@6bbef70
Using strategy: Default
Cloning the remote Git repository
Cloning repository ssh://git@10.10.2.40:7999/AT/repository1.git
git --version
git version 1.7.12.4
ERROR: Error cloning remote repo 'origin' : Could not clone ssh://git@10.10.2.40:7999/AT/repository1.git
hudson.plugins.git.GitException: Could not clone ssh://git@10.10.2.40:7999/AT/repository1.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:273)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1044)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:986)
    at hudson.FilePath.act(FilePath.java:852)
    at hudson.FilePath.act(FilePath.java:825)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1324)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581)
    at hudson.model.Run.execute(Run.java:1518)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: hudson.plugins.git.GitException: Command "/home/danilo/libexec/git-core/git clone --progress -o origin ssh://git@10.10.2.40:7999/AT/repository1.git /var/lib/jenkins/jobs/Test Job/workspace" returned status code 128:
stdout: Cloning into '/var/lib/jenkins/jobs/Test Job/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.

    at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:897)
    at hudson.plugins.git.GitAPI.access$000(GitAPI.java:42)
    at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:269)
    at hudson.plugins.git.GitAPI$1.invoke(GitAPI.java:248)
    at hudson.FilePath.act(FilePath.java:852)
    at hudson.FilePath.act(FilePath.java:825)
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:248)
    ... 14 more
Trying next repository
ERROR: Could not clone repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1056)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:986)
    at hudson.FilePath.act(FilePath.java:852)
    at hudson.FilePath.act(FilePath.java:825)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1324)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581)
    at hudson.model.Run.execute(Run.java:1518)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)

2 个答案:

答案 0 :(得分:3)

我遇到了类似的问题 - 您需要将您的存储服务器添加到jenkins服务器上的known_hosts。

登录您的jenkins服务器并ssh到您的存储服务器。这将在用户的known_hosts文件中为存储服务器添加一个条目。

然后将known_hosts文件复制到$ JENKINS_HOME / .ssh并将文件所有者更改为jenkins。

答案 1 :(得分:0)

我通过使用通常看起来像SCP命令的无效URL得到了同样的错误,这与git命令不同。

我最初有:

ssh://jenkins@machinename:~/repos/newrepo.git

改为:

ssh://jenkins@machinename/~/repos/newrepo.git

我正在为詹金斯做准备。一旦我在命令行上正常工作,那么我在Jenkins的工作就可以了。