简体   繁体   中英

Jenkins Poll SCM (Git) on Windows master / Build on Linux slave

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:
    1. Open node configuration page (Configure icon)
    2. Check "Tool Locations" if not already checked
    3. Click "Add"
    4. Select "(Git) Default" on the dropdown
    5. Enter the path to the slave node git installation (eg /usr/local/bin/git )
    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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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