简体   繁体   English

Jenkins Windows Slave没有为git使用正确的凭据

[英]Jenkins Windows Slave not using correct credentials for git

I have a Jenkins master (ubuntu) that uses a Windows slave to build a UWP app. 我有一个使用Windows从站构建UWP应用程序的Jenkins主站(ubuntu)。 When it is trying to run a git fetch I get the following error:- 当它尝试运行git fetch时,出现以下错误:-

git fetch --tags --progress git@gitlab.com:user/repo.git +refs/heads/*:refs/remotes/origin/*
23:24:08 ERROR: Error fetching remote repo 'origin'
23:24:08 hudson.plugins.git.GitException: Failed to fetch from git@gitlab.com:user/repo.git
23:24:08    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:803)
23:24:08    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1063)
23:24:08    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1094)
23:24:08    at hudson.scm.SCM.checkout(SCM.java:495)
23:24:08    at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
23:24:08    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:560)
23:24:08    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
23:24:08    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:485)
23:24:08    at hudson.model.Run.execute(Run.java:1735)
23:24:08    at hudson.matrix.MatrixRun.run(MatrixRun.java:153)
23:24:08    at hudson.model.ResourceController.execute(ResourceController.java:97)
23:24:08    at hudson.model.Executor.run(Executor.java:405)
23:24:08 Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --progress git@gitlab.com:user/repo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
23:24:08 stdout: 
23:24:08 stderr: jenkins_user@gitlab.com: Permission denied (publickey).
23:24:08 fatal: Could not read from remote repository.

It seems to be using the wrong email address to fetch the repository. 似乎使用了错误的电子邮件地址来获取存储库。 It should be jenkins_user@domain.com not @gitlab.com but even if I do a git config --global user.email jenkins_user@domain.com it still gives the same error. 它应该是jenkins_user@domain.com而不是@ gitlab.com,但是即使我执行git config --global user.email jenkins_user@domain.com它仍然会给出相同的错误。

This is probably not related to user.email config in your local repository. 这可能与本地存储库中的user.email配置无关。

When jenkins slave is installed as a Windows service (to ensure the agent runs even if nobody login on the machine), the user that runs jenkins binary is the Local System Account. 当jenkins slave作为Windows服务安装(以确保即使没有人登录时代理也可以运行)时,运行jenkins二进制文件的用户是本地系统帐户。 You have to create a SSH public/private key pair and put it under the right folder on your machine: 您必须创建一个SSH公/私钥对,并将其放在计算机上的正确文件夹下:

C:\Windows\system32\config\systemprofile\.ssh

You will also need to copy a proper known_hosts file, to ensure the first git pull will work without asking to type yes on the command line (impossible from a jenkins job). 您还需要复制一个适当的known_hosts文件,以确保第一个git pull可以正常工作,而无需在命令行上键入yes (在jenkins作业中这是不可能的)。

Warning : Most of the time, when Windows Update perform a system upgrade, this folder is cleaned and you lost your key. 警告:在大多数情况下,Windows Update执行系统升级时,将清除此文件夹,并且您丢失了密钥。 You will have to save the files somewhere else to ensure you can restore them after an upgrade. 您必须将文件保存在其他位置,以确保升级后可以将其还原。

See this post for additional information, or search for "ssh key local system account" on your preferred search engine. 有关其他信息,请参阅此帖子 ,或者在您首选的搜索引擎上搜索“ ssh key本地系统帐户”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM