【问题标题】:Jenkins and Stash setup ssh keyJenkins 和 Stash 设置 ssh 密钥
【发布时间】:2012-11-27 16:57:52
【问题描述】:

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

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

全局配置用户名值

全局配置 user.email 值

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

存储库网址: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)

【问题讨论】:

  • 可以使用ssh命令连接repository服务器吗?

标签: git ssh jenkins bitbucket-server


【解决方案1】:

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

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

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

【讨论】:

  • 对我来说只是 ssh 不起作用,我不得不尝试为 known_hosts 克隆一个 ssh 存储库以添加正确的密钥
【解决方案2】:

我有一个无效的 URL,它通常看起来像一个 SCP 命令,这与 git 命令不同。

我原来有:

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

并改为:

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

我正在为詹金斯做准备。一旦我让它在命令行中正常工作,那么我在 Jenkins 的工作就很好了。

【讨论】:

    猜你喜欢
    • 2022-09-23
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多