繁体   English   中英

如何使用 Jenkins Freestyle Project 访问远程 Git 存储库

[英]How to access remote Git repositories using Jenkins Freestyle Project

我在我的 Mac 中安装了jenkins.war ,它是我的/Users/myuser/jenkins folder中的 jenkins.war 。 第一次运行它,Jenkins 创建/Users/mysuer/.jenkins文件夹并在那里部署人工制品。 运行它我要去/Users/myuser/jenkins/java -jar jenkins.war

此外,我创建了自由样式项目,它使用 Git 作为源代码存储库,并且假设每 5 分钟连接到外部存储库,该存储库位于树莓派 4 中。

设置一个生成到 MacOS 端的 rsa ssh 密钥,并使用它通过 ssh 连接到树莓,这没有任何问题。

另外在 Jenkins 凭证上设置如下:

Scope: Global (Jenkins, nodes ... )
Id: Some id
Description: Some description
Username: My-MacOS-User
Private Key: The private key generate into my Mac side (id_rsa)
Password: The private key passoword

当尝试运行项目时,总是得到:

Failed to connect to repository : Command "git ls-remote -h -- ssh://pi@raspberrypi/home/pi/server/git/myRepo HEAD" returned status code 128:
stdout: 
stderr: Permission denied, please try again. 
Permission denied, please try again. 
pi@raspberrypi: Permission denied (publickey,password). 
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Uploaded the public and the private key into /home/pi/.ssh , created .ssh folder into the ./.jenkins folder with the id_rsa and id_rsa.pub Added the .ssh to the ./jenkins folder too Created a config file

而且它们似乎都不起作用....

任何想法如何正确设置

终于我可以做到了!

不要忘记在凭据中使用用户 pi。

另外一个问题是生成的密钥没有注册到 ssh-agent 中,因此 Jenkins 在尝试向 Raspberry Pi 进行身份验证时找不到密钥。

要注册密钥,只需按照生成新的 SSH 密钥并将其添加到 ssh-agent 中的说明进行操作

添加密钥后......瞧......一切都很完美!

在 Raspberry 端仔细检查公钥( id_rsa.pub )是否已添加到~pi/.ssh/authorized_keys

Jenkins 需要连接到该树莓盒。

您不必将这些密钥上传到/home/pi/.ssh (尤其是私钥,顾名思义,应该保持私有)


另外在 Jenkins 凭证上设置如下:

 Scope: Global (Jenkins, nodes... ) Id: Some id Description: Some description Username: My-MacOS-User <<===== should be pi Private Key: The private key generate into my Mac side (id_rsa) Password: The private key passoword

Jenkins 应使用远程帐户“pi”而不是本地 MacOS 帐户来使用 SSH 凭据。

暂无
暂无

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

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