在Jenkins中使用execute shell命令在Windows机器上运行git命令 [英] Using the execute shell command in Jenkins to run git commands on a Windows machine

查看:2052
本文介绍了在Jenkins中使用execute shell命令在Windows机器上运行git命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行一个定期删除旧的git分支的bash脚本。我无法找到通过执行shell选项连接到git repo的方法。

I need to run a bash script that periodically deletes old git branches. I am having trouble finding a way to connect to the git repo via the execute shell option.

目前我正在使用cygwin来运行git命令。下面是我在执行shell中的内容:

Currently I am using cygwin in order to run git commands. Here is what I have in execute shell:

#!c:\cygwin64\bin\bash --login
git ls-remote git@10.1.1.126:/external-web/collette-com.git 

该命令抛出以下错误。

This command is throwing the following error.

[Delete Branches] $ c:\cygwin64\bin\bash --login 

C:\Users\tbraga\AppData\Local\Temp\hudson5750784484659728632.sh
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Build step 'Execute shell' marked build as failure

我试着在命令行并提示输入密码。难道这是问题吗?

I have tried running this command in the command line and am prompted for a password. Could this be the issue?

我在Jenkins中配置了git插件,使用源代码管理Git时连接完美。

I have the git plugin configured within Jenkins and the connection works perfectly when using Source Code Management Git.

有关如何使这种连接在执行shell字段中工作的任何建议将不胜感激。

Any suggestions on how to make this connections work in the execute shell field would be greatly appreciated.

推荐答案

我使用SSH密钥作为身份验证给Github并产生了同样的问题。我的Jenkins配置有EC2从属,所以机器上的默认SSH密钥对Github不正确。

I use SSH keys for auth to Github and had this same issue. My Jenkins configuration has EC2 slaves, so the default SSH key on the machine wasn't correct for Github.

我使用 SSH代理插件。在作业中,启用SSH代理设置并为Github认证选择存储的SSH密钥。它应该与用于克隆repo的Git-SCM配置选择的一样。

I fixed it with the SSH Agent Plugin. In the job, enable the "SSH Agent" setting and choose the stored SSH key for Github authentication. It should be the same one selected for the Git-SCM configuration used to clone the repo.

这篇关于在Jenkins中使用execute shell命令在Windows机器上运行git命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆