简体   繁体   English

将Git与Jenkins搭配使用私人git回购

[英]Using Git with Jenkins with a private git repo

I am having trouble getting Git to work with Jenkins. 我很难让Git与Jenkins合作。 I've setup a private git repo using gitblit on a windows 2008 server machine. 我已经在Windows 2008服务器计算机上使用gitblit设置了一个私人git repo。 I've created an account in gitblit to be used by jenkins (ie: username: jenkins, password: password, company: test). 我已经在gitblit中创建了一个供jenkins使用的帐户(即:用户名:jenkins,密码:password,公司:test)。 I've created the certificates and allowed access using both ssh and https. 我已经创建了证书,并允许使用ssh和https进行访问。

Using the command prompt, I am able to get cloning to work by typing the following command in command line: 使用命令提示符,我可以通过在命令行中键入以下命令来使克隆工作:

git clone ssh://jenkins@repo.test.com:29418/testrepo/WebApp.git c:\test

The above command asks me for a password before retrieving the code. 上面的命令在检索代码之前要求我输入密码。 Since I am trying to script this in Jenkins, I try: 由于我试图用詹金斯编写脚本,因此我尝试:

git clone ssh://jenkins:password@valrepo.test.com:29418/testrepo/WebApp.git c:\test

but I get the following error: 但我收到以下错误:

ssh: Could not resolve hostname jenkins: no address associated with name
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

Well ok, so let me try the https command. 好吧,让我尝试https命令。 So I try the following: 因此,我尝试以下操作:

git https://jenkins@valrepo.test.com/r/testrepo/WebApp.git C:\test

but got the following error: 但出现以下错误:

fatal: unable to access 'https://jenkins@valrepo.test.com/r/testrepo/WebApp.git/': SSL certificate problem: self signed certificate in certificate chain

So I figure why not try the sslVerify=false command. 所以我想为什么不尝试sslVerify = false命令。 I give the following a try in the command prompt: 我在命令提示符下尝试以下操作:

git -c http.sslVerify=false clone https://jenkins@valrepo.test.com/r/testrepo/WebApp.git C:\test

and it works in the command prompt. 它在命令提示符下工作。 However, when I try it in Jenkins as a script command, Jenkins just ends up hanging without downloading anything. 但是,当我在Jenkins中将其作为脚本命令尝试使用时,Jenkins最终会挂起而没有下载任何内容。 No idea why. 不知道为什么。

Other things that I have tried is to use the built-in Git plugin, but I cannot get that to work either. 我尝试过的其他方法是使用内置的Git插件,但是我也无法正常工作。

I am running out of ideas on how to get this to work in Jenkins. 我没有关于如何使它在詹金斯上工作的想法。 Anyone have any experience? 有人有经验吗?

I was able to fix it by login in as the SYSTEM account using PSEXEC (Jenkins runs under system account) and adding the certificate to the git repo using the following commands: 我可以通过使用PSEXEC(Jenkins在系统帐户下运行)作为SYSTEM帐户登录并使用以下命令将证书添加到git repo来修复该问题:

git config --global http.sslCert path/to/jenkins.pem
openssl rsa -in path/to/jenkins.pem -out path/to/jenkins.key    
git config --global http.sslKey path/to/jenkins.key

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

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