简体   繁体   English

jenkins下的git clone / ssh

[英]git clone/ssh under jenkins

I am using stash as a git repository manager. 我使用stash作为git存储库管理器。 stash enables you to add ssh keys for each user trying to connect and clone from it. stash使您可以为尝试连接和克隆的每个用户添加ssh密钥。 I have configured it fine for all unix users but windows is giving me hard times. 我已经为所有unix用户配置好了,但是Windows给了我很多困难。 the git clone process on the windows slave machine (2008 R2 server) hangs forever since it probably doesn't find the .ssh directory, where the keys are kept. Windows从机(2008 R2服务器)上的git clone进程永远挂起,因为它可能找不到保存密钥的.ssh目录。 when running the same command manually from cli, it works fine. 当从cli手动运行相同的命令时,它工作正常。

I have tried all sorts of configurations, played with %HOME% env variable,etc. 我尝试了各种配置,使用%HOME%env变量等。 it simply won't work for me. 它根本不适合我。 spent more then a day on this issue but nothing worked. 在这个问题上花了一天多的时间但没有任何效果。

any help is appreciated. 任何帮助表示赞赏。

On the client side (Jenkins), you need to check if the user running the Jenkins Jobs knows about a %HOME% environment variable: it needs its %HOME%.ssh\\id_rsa.pub public ssh key there. 在客户端(Jenkins),您需要检查运行Jenkins Jobs的用户是否知道%HOME%环境变量:它需要%HOME%.ssh \\ id_rsa.pub公共ssh密钥。
See " Jenkins - Git - Permission denied (publickey) " 请参阅“ Jenkins - Git - 权限被拒绝(公钥)

On the server ( Stash from Atlassian ), you need to make sure the ~stachAadminAccount\\.ssh\\authorized_keys does contain your public key. 在服务器上( 来自Atlassian的Stash ),您需要确保~stachAadminAccount\\.ssh\\authorized_keys确实包含您的公钥。

Beside that, you need to debug the ssh connexion: 除此之外,您需要调试ssh连接:

ssh -vvvT ssh://git@stash.atlassian.com:7999/path/to/repo.git

(replacing git by the account used for administrating Stash, and replacing stash.atlassian.com:7999 by your server:port ) (用管理Stash的帐户替换git ,并用server:port替换stash.atlassian.com:7999


1) I have explicitly added %HOME% to the system env vars on the slave , just to make sure it's injected in. it may not be needed but I added it to see if it will have an affect 1)我已经明确地将%HOME%添加到奴隶的系统环境中,只是为了确保它被注入。它可能不需要但我添加它以查看它是否会产生影响

It is needed : ssh will look for keys (private and public) under %HOME%/.ssh 需要 :ssh将在%HOME%/.ssh下查找密钥(私有和公共)

2) I never had to mess with ssh keys under stash. 2)我从来没有在stash下乱用ssh键。 in fact, all the users for stash are internal to stash and are not part of the /etc/password file or anything like that, so no authorized_keys file exists anyway – user1577236 7 hours ago 事实上,存储的所有用户都是存储内部的,并且不属于/etc/password文件或类似的东西,因此无论如何都不存在authorized_keys文件 - user1577236 7小时前

a/ " not part of the /etc/password file": Sure those are not registered in /etc/password: we are not talking about user account here, but about ssh keys allowing a user to open a secure shell session as one unique user account (the stash admin account): all ssh commands will be executed under the same account. a /“不是/etc/password文件的一部分”:当然这些没有在/ etc / password中注册:我们不是在这里讨论用户帐户,而是关于允许用户打开安全shell会话的ssh密钥作为一个唯一的用户帐户(存储管理员帐户):所有ssh命令将在同一帐户下执行。

b/ "no authorized_keys file": of course it should exist: when you are reporting that a clone with ssh protocol works, it involves a pure ssh communication, which means looking for public key on the server side in a ~/.ssh/authorized_keys . b /“no authorized_keys文件”:当然它应该存在:当你报告带有ssh协议的克隆工作时,它涉及纯ssh通信,这意味着在服务器端查找~/.ssh/authorized_keys
The only way that file doesn't exist is if Stash launch its own ssh daemon, configured to look for keys in another file/source of public keys. 文件不存在的唯一方法是Stash启动自己的ssh守护程序,配置为在另一个文件/公钥源中查找密钥。

regarding 2 - what you do in stash is to add the public key into a spacial place in stash, for each user. 关于2 - 你在stash中做的是将公钥添加到存储的空间位置,供每个用户使用。

That may be, but Stash should just be a nice front-end for ssh. 这可能是,但Stash应该只是ssh的一个不错的前端。 All the ssh mechanism behind it should still be updated. 它背后的所有ssh机制仍应更新。

3) as mentioned, running the git clone command from the command line with git ssh protocol works fine, so what should I be looking for in the debug session ? 3)如上所述,使用git ssh协议从命令行运行git clone命令工作正常,那么我应该在调试会话中寻找什么?

You must define a Jenkins job which does the ssh -vvvT as its sole command: that way, you would see what doesn't work from the Jenkins perspective. 您必须定义一个Jenkins作业,该作业将ssh -vvvT作为其唯一命令:这样,您将看到Jenkins透视图中不起作用的内容。

I would love to debug the Jenkins process and to see what it does during it's ssh session, but I don't know how to do that ( yet...). 我想调试Jenkins进程并查看它在ssh会话期间的作用,但我不知道该怎么做(还有......)。 just started to work with Jenkins 2 weeks ago or so. 刚刚开始与Jenkins合作2周前左右。

On windows, a process explorer is at least one first step in order to see under which account, and with what environment variable the Jenkins process (and its jobs) are running. 在Windows上, 进程资源管理器至少是第一步,以便查看哪个帐户以及Jenkins进程(及其作业)正在运行的环境变量。

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

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