如何在Jenkins中的ssh-agent上直接在Windows上使用git [英] How to use git directly on Windows with ssh-agent in Jenkins

查看:152
本文介绍了如何在Jenkins中的ssh-agent上直接在Windows上使用git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将裸git repo作为构建的一部分进行更新.在Linux上相对简单:

I'm trying to update bare git repo as part of build. On Linux it was relatively simple:

dir("/my/git/repo.git") {
    sshagent(['git']) {
        sh "git fetch origin module:module"
    }
}

但是我不知道如何在Windows上执行该操作.我试过了:

However I cannot figure out how to do it on Windows. I tried:

dir("c:\\my\\git\\repo.git") {
    withEnv(["PATH=${env.PATH};C:\\Program Files\\Git\\usr\\bin"]) {
        sshagent(['git']) {
            sh "git fetch origin module:module"
        }
    }
}

但是失败了:

Could not find ssh-agent: IOException: Cannot run program "ssh-agent": CreateProcess error=2, The system cannot find the file specified
Check if ssh-agent is installed and in PATH

我该怎么办?

推荐答案

我在以下位置看到了ssh-agent:

I see ssh-agent in:

C:\>where ssh-agent
C:\tools\gits\latest\usr\bin\ssh-agent.exe

您需要确保您的%PATH%(由执行Jenkins作业的用户看到)包括Git\binGit\usr\binGit\mingw64\bin.
(用Git安装路径文件夹替换Git)

You need to make sure your %PATH% (as seen by the user executing the Jenkins job) includes Git\bin, Git\usr\bin, Git\mingw64\bin.
(Replace Git by the Git installation path folder)

执行任务(甚至失败)后,查找环境变量"链接:您将确切看到谁在运行任务(USERNAME)和使用的PATH.

After executing a job (even failed), look for the link "Environment Variables": you will see exactly who was running the job (USERNAME) and the PATH used.

这篇关于如何在Jenkins中的ssh-agent上直接在Windows上使用git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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