本文介绍了Jenkins在Windows主站/在Linux从站上构建SCM(Git)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的场景:


  • 使用git作为我的SCM

  • Jenkins作业运行Linux从服务器

  • Jenkins主服务器托管在Windows上





我相信当你需要多个git安装或者你时,@Jayan提到的额外的git安装更合适出于某种原因,需要运行特定版本的git以选择Jenkins作业。

Here is my scenario:

  • Using git as my SCM
  • Jenkins Job runs on Linux slave
  • Jenkins master is hosted on Windows

I have configured two Git installations as indicated in Jenkins path to git Windows master / Linux slave. Git installations are set up as follows:

  • Name: WindowsGit | Path: C:\Program Files\Git\bin\git.exe
  • Name: LinuxGit | Path: /usr/local/bin/git

Because I need to run the job on linux slave, my job git configuration is pointing to LinuxGit (Git executable option). Job runs great, no problems. However, when I try to use "Poll SCM" option, it breaks. I believe the problem here is because Poll SCM runs on the Windows Master and the Git information for this job is pointing to LinuxGit. Git Polling Log shows:

Caused by: java.io.IOException: Cannot run program "/usr/local/bin/git": CreateProcess error=2, The system cannot find the file specified

In the other hand, if I select WindowsGit, Git Polling Log is fine but job itself will obviously fail because it's running on a Linux Slave.

Question:Can anyone think about a way I can select one Git installation for the Source Code Management configuration and another one for the Poll SCM feature?

解决方案

As requested, I'm posting my own answer to the general idea, for mixing Windows/Linux on Master Slaves when working with git. This solution will allow even to run the same job on multiple mix of Windows/Linux slaves as well as won't break Master polling scm:

Whatever you Jenkins Master platform is, configure the default git installation to point to a valid git for that platform. For example, c:\apps\git\bin\git.exe for Windows. and then configure the custom "Tool Locations" for each node. This way the master will be able to poll git to check for changes and trigger the job on a slave. The Slave will then be capable to clone the git code because it has its custom location for (Git) Default. Steps to configure properly:

  1. Manage Jenkins > Manage Nodes
  2. For each node having git location other than the one provided in the "Git installation", do:2.1 Open node configuration page (Configure icon)2.2 Check "Tool Locations" if not already checked2.3 Click "Add"2.4 Select "(Git) Default" on the dropdown2.5 Enter the path to the slave node git installation (e.g. /usr/local/bin/git)2.6 Save
  3. Repeat steps 2.1 to 2.5 for each Linux slave the job may run.

Node configuration for the linux slave node should look something like this:

I believe the additional "git installations" are more suitable, as @Jayan mentioned, when you need to have multiple git installations or you need to run, for some reason, a specific version of git for select Jenkins jobs.

这篇关于Jenkins在Windows主站/在Linux从站上构建SCM(Git)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 08:58