1

我从 homebrew ( brew install jenkins) 安装了 Jenkins CI。所以,它在我自己的用户下运行。除了对我的 Git 存储库的 SSH 访问之外,一切正常。我不想创建一个单独的用户(例如 jenkins)来运行 Jenkins 并为其创建单独的 SSH 密钥。我只想使用我自己的 SSH 密钥。在命令行上访问我的远程 git repo 可以使用我的 ssh 密钥正常工作,但在 Jenkins 中它不起作用。它给出了“权限被拒绝(公钥)”错误(用户名和项目被混淆(<user><project>)):

Started by user anonymous
Checkout:workspace / /Users/<user>/.jenkins/jobs/<project>_run_tests/workspace - hudson.remoting.LocalChannel@456d3d51
Using strategy: Default
Last Built Revision: Revision 093f1641f26632afd1a74c14276ec544356c1d08 (origin/dev)
Checkout:workspace / /Users/<user>/.jenkins/jobs/<project>_run_tests/workspace - hudson.remoting.LocalChannel@456d3d51
Fetching changes from 1 remote Git repository
Fetching upstream changes from ssh://git@bitbucket.org/<user>/<project>.git
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
ERROR:  (Underlying report) : Error performing command: /usr/local/bin/git fetch -t ssh://git@bitbucket.org/<user>/<project>.git +refs/heads/*:refs/remotes/origin/*
Command "/usr/local/bin/git fetch -t ssh://git@bitbucket.org/<user>/<project>.git +refs/heads/*:refs/remotes/origin/*" returned status code 128: Permission denied (publickey).
fatal: The remote end hung up unexpectedly

ERROR: Could not fetch from any repository
FATAL: Could not fetch from any repository
hudson.plugins.git.GitException: Could not fetch from any repository
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1012)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:972)
    at hudson.FilePath.act(FilePath.java:783)
    at hudson.FilePath.act(FilePath.java:765)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:972)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1195)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:568)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:457)
    at hudson.model.Run.run(Run.java:1404)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:230)

似乎它没有使用我的 ssh 密钥连接到 git 服务器。我尝试将 UserName 密钥添加到 jenkins launchagent plist,重新启动,但没有效果。

如何让 jenkins 使用我的 SSH 密钥连接到我的远程 git repo?

4

1 回答 1

2

我不知道自制软件如何设置 Jenkins,但显然它是在无法访问您的 ssh 代理并且您的 ssh 密钥受密码保护的上下文中运行的。

当您在终端窗口中运行它时,您的环境中有 SSH_AUTH_SOCK 变量,ssh 客户端使用该变量进行身份验证。如果您无法使用 ssh 代理,则需要从 ssh 密钥中删除密码。

于 2012-03-22T22:54:00.950 回答