4

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?

Community
  • 1
  • 1
L. Holanda
  • 4,432
  • 1
  • 36
  • 44
  • Does master have git installed? Could you adjust the PATH for having it in path? I admit having Jenkins master on linux is much better. I do not have any windows master to try... – Jayan Mar 08 '16 at 03:35
  • Yes. I found the solution. Having a single git installation setup with master installation and then using node configuration to override widows git path with Linux got path seems to be the best option. See my answer in the other question (35223071). Should apply there too. – L. Holanda Mar 08 '16 at 07:54
  • I believe this question can be marked as duplicate. The question is slightly different, but the answer is the same that applies to 35223071 by using the Manage Nodes option. – L. Holanda Mar 08 '16 at 17:44
  • What about moving that answer here. This question is google friendly. . – Jayan Mar 09 '16 at 03:09

1 Answers1

6

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 (e.g. /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:

slave node configuration

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.

Szymon Kuzniak
  • 848
  • 1
  • 6
  • 16
L. Holanda
  • 4,432
  • 1
  • 36
  • 44
  • Master is linux with git installed. Slave is windows without git. Jenkinsfile (pipeline) is in git repository. Intention is to create a folder in workspace on slave node (no git required). Even if I mention the agent any, while running the job it try to fetch the Jenkinsfile from git on slave node. Why it so? Shouldn't it fetch the pipeline on master and then for creating folder check the agent again and run on particular node? please suggest – Mohit Aggarwal Jan 01 '20 at 09:40