自制软件安装的 Mac OS X 上的 Jenkins SSH 问题

发布于 2024-12-18 06:57:46 字数 2774 浏览 2 评论 0原文

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

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://[email protected]/<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://[email protected]/<user>/<project>.git +refs/heads/*:refs/remotes/origin/*
Command "/usr/local/bin/git fetch -t ssh://[email protected]/<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 存储库?

I installed Jenkins CI from homebrew (brew install jenkins). So, it runs under my own user. Everything works fine except for SSH access to my Git repository. I do not want to create a separate user (e.g. jenkins) to run Jenkins and create separate SSH keys for it. I just want to use my own SSH keys. Accessing my remote git repo on the command-line works fine with my ssh keys, but in Jenkins it does not work. It gives a 'Permission denied (publickey)' error (username and project are obfuscated (<user> and <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://[email protected]/<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://[email protected]/<user>/<project>.git +refs/heads/*:refs/remotes/origin/*
Command "/usr/local/bin/git fetch -t ssh://[email protected]/<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)

It seems it is not using my ssh keys to connect to the git server. I tried adding a UserName key to the jenkins launchagent plist, did a restart, but no effect.

How can I make jenkins use my SSH keys to connect to my remote git repo?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

公布 2024-12-25 06:57:46

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

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

I do not know how homebrew sets up Jenkins, but apparently it is running in a context where it has no access to your ssh agent and your ssh key is passphrase-protected.

When you run it in a Terminal window, you have SSH_AUTH_SOCK variable in your environment which ssh client uses to authenticate. If you cannot use the ssh agent, you need to remove the passphrase from the ssh key.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文