2017-10-07 33 views
2

我试图更新裸git回购作为生成的一部分。在Linux上它是相对简单的:如何直接在Windows上使用git与詹金斯ssh代理

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

但是我无法弄清楚如何在Windows上做到这一点。我想:

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 

我该怎么办呢?

回答

1

我看到的ssh-agent在:

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

你需要确保你的%PATH%(执行詹金斯作业的用户可以看到)包括Git\binGit\usr\binGit\mingw64\bin
(由Git的安装路径文件夹替换Git

执行作业(甚至失败)后,查找链接“环境变量”:你会看到究竟谁在运行作业(USERNAME)和使用的PATH

+0

谢谢。所以通过'withEnv'设置不起作用... –