我从自制程序(brew install jenkins
)安装了Jenkins CI。所以,它在我自己的用户下运行。一切正常,除了SSH访问我的Git存储库。我不想创建一个单独的用户(例如jenkins)来运行Jenkins并为它创建单独的SSH密钥。我只想使用自己的SSH密钥。在命令行上访问我的远程git repo可以正常使用我的ssh密钥,但在Jenkins中它不起作用。它给出了“Permission denied(publickey)”错误(用户名和项目被混淆了(<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的激活plist,重新启动,但没有效果。
如何让jenkins使用我的SSH密钥连接到我的远程git仓库?
答案 0 :(得分:2)
我不知道自制软件是如何设置Jenkins的,但显然它是在一个无法访问你的ssh代理的环境中运行的,而你的ssh密钥是受密码保护的。
在终端窗口中运行它时,您的环境中有SSH_AUTH_SOCK变量,ssh客户端使用该变量进行身份验证。如果您无法使用ssh代理,则需要从ssh密钥中删除密码。