2011-06-29 265 views
11

我在Win 2008服务器上设置Jenkins,并且在配置Jenkins连接到GitHub时遇到了一些问题。我得到以下错误:设置Jenkins时权限被拒绝(publickey)

Command "git.exe fetch -t [email protected]:USER/REPO.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:950) 
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:908) 
    at hudson.FilePath.act(FilePath.java:758) 
    at hudson.FilePath.act(FilePath.java:740) 
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:908) 
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1184) 
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:537) 
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:425) 
    at hudson.model.Run.run(Run.java:1376) 
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46) 
    at hudson.model.ResourceController.execute(ResourceController.java:88) 
    at hudson.model.Executor.run(Executor.java:175) 

事情我已经检查

  • 詹金斯服务是我的用户名下运行。
  • 我更改了我的SSH密钥,使其不再有密码。
  • 我已通过使用msysgit执行与Jenkins相同的命令验证了我的SSH密钥是否有效。
  • 验证我所有的路径都是正确的。

詹金斯配置设置

  • 詹金斯1.418
  • GitHub的插件0.5
  • GIT中插件1.1.9

msysgit运作,但CMD提示不 当我导航到一个有效的回购并从DOS提示符执行命令,它也失败。

你知道我可能错过了什么吗?

感谢您的帮助。

+0

这是一个私人回购?如果没有,您可以使用Git协议URL进行克隆(git://github.com/USER/REPO.git),完全避免使用SSH密钥。 – leedm777

+2

你确定你已经定义了一个HOME环境变量吗?它在Windows上没有默认定义。 – VonC

+0

VonC,谢谢!你钉了它。请发布答案,以便我可以将其标记为已接受。我感谢您的帮助。 –

回答

13

正如我所说,使用ssh协议时,指定HOME环境变量是关键。
由于Windows没有HOME,所以您需要明确地将其定义为任何您想要的目录。

然而,Vestnik评论:

I've specified to override HOME on the windows slave node to point it to C:\jenkins .
I've put correct id_rsa under the C:\jenkins\.ssh but still have this issue.
My slave agent running as service under SYSTEM account.

两个建议:

  • 您需要使您的从属显示屏'set'以检查与SYSTEM帐户一起使用时是否定义了HOME。
    如果不是,那可能意味着您需要将该变量添加到“系统环境变量”,而不是“用户环境变量”。

display env from the job definition

  • 不要忘记必须在%HOME%\.ssh目录都id_rsaid_rsa.pub:你既需要公共和私有SSH密钥。(如“git clone with ssh issue”提到)

如果你有一个参数化的构建,也can define HOME that way,并检查你的奴隶拿起了HOME权值:

define custom variables

+1

谢谢你的详细解答。当我将公钥放到远程$ {HOME} /。ssh/ – VestniK

+0

@VestniK时,问题就解决了:优秀!很高兴你做到了。 – VonC

+0

要正确使用“HOME”变量,您需要确保它在Windows和Jenkins中均已指定。在命令提示符下进行测试:'echo%HOME%'如果输出只是'%HOME%',则需要在Windows的'控制面板>系统>高级系统设置>环境变量'中设置HOME变量。在上面的例子中,变量的值需要是'C:\ jenkins'。测试它是由**重新启动**命令提示符并运行'echo%HOME%'设置的。输出现在应该是'C:\ jenkins' – MrOodles

4

有两个插件在与可以使用的ssh相关的jenkins中:Publish Over SSHJenkins SSH plugin

第一个插件给出了设置全局ssh密钥的可用性,第二个插件给出了设置各种ssh密钥的可用性。

接下来,您需要再安装两个插件,这些插件将用于项目配置GitHub PluginJenkins Git Plugin

GitHub插件将用于设置GitHub项目。 Jenkins Git插件将用于设置“存储库的URL”和其他事物,比如分支等。

所有插件都可以从Jenkins插件管理器中的可用选项卡获得。

my blog post, on the topic复制:

Jenkins configuration:
The Jenkins SSH plugin give the availability to set private key per host, the second plugin do the job for a global host.
If Jenkins SSH plugin is used, then in SSH remote hosts write the host, user, passphrase and the path to the private key.
If Publish Over SSH is used, then in SSH setting write the passphrase and paste the private key or write the path to it.
The project configuration is:
GitHub Project https://github.com/GitUser/iOS-project/
*Source Code Management
-> Git
-> -> Repositories
-> -> -> URL of repository: [email protected]:GitUser/iOS-project.git
-- It is up to you configure a branch or take the default one --
*Build Triggers
-> Poll SCM -- Seted --
-> Schedule: * * * * *
*Build
-> Executed Shell

-> -> Command: xcodebuild -target iOS-project -configuration AdHoc -sdk iphoneos5.0 clean 
-> -> Command: agvtool new-version -all $BUILD_NUMBER 
-> -> Command: xcodebuild -target iOS-project -configuration AdHoc -sdk iphoneos5.0 
-> -> Command: xcrun -sdk iphoneos5.0 PackageApplication -v $WORKSPACE/build/AdHoc-iphoneos/iOS-project.app -o $WORKSPACE/build/AdHoc-iphoneos/iOS-project-$BUILD_NUMBER.ipa PROVISIONING_PROFILE="<provisioning profile>" 
-> -> Command: curl http://testflightapp.com/api/builds.json -F [email protected]$WORKSPACE/build/AdHoc-iphoneos/iCushion-1.0-$BUILD_NUMBER.ipa -F api_token=<api_token> -F team_token=<team_token> -F notes="This is an autodeploy build from Jenkins!" -F notify=True -F distribution_lists="<distributedlist 1>, <distributedlist 2>" 
0

看来git的插件,现在提供了一种指向詹金斯到主目录。

  1. 单击凭证添加按钮。

enter image description here

  • 点詹金斯将私钥。
  • enter image description here

  • 从列表中选择新添加的凭证。
  • enter image description here

    0

    在我的环境(詹金斯64位与Java 32位,在Windows Server上运行2016 64位),将溶液放入C中的关键:\ WINDOWS \ SysWOW64 \ config \ systemprofile \ .ssh文件夹。根据Git Plugin documentation

    By default, the Jenkins Windows installer sets up Jenkins to run as a service on Windows, which runs as the “Local System account”, NOT your user account. Since the “Local System account” does not have SSH keys or known_hosts set up, “git clone” will hang during the build. It's possible to keep Jenkins running as the “Local System account” and clone repositories via SSH by making sure that the “Local System account” is set up with a properly configured .ssh directory (i.e. id_rsa, id_rsa.pub, AND known_hosts)

    相关问题