13

I have a Jenkins master on Windows which runs some Windows builds.

The git client plugin in configured with a fixed path to git as "C:\Program Files (x86)\git\bin\git.exe"

I've now created a Linux slave, but when I run a job on there, it's trying to run the command "C:\Program Files (x86)\git\bin\git.exe init", and obviously fails.

Is there a simple solution to this? I think I've resolved it already by modifying PATH on the Windows master, and the fixed path to git is now just "git" so would work on both OSs.

Is the "correct" way to resolve this for Jenkins, or is there another/better way to do this?

Thanks.

Steve Folly
  • 8,327
  • 9
  • 52
  • 63

4 Answers4

11

My problem was slightly different, but my solution also applies for this question here. Jenkins Poll SCM (Git) on Windows master / Build on Linux slave

When using the "Git installations" option, you will need to create different jobs, one with each Git Installation. Modifying the PATH either on windows or linux, sometimes might not be an option (in my case, I only have access to Jenkins web UI).

Instead, just make the Default Git installation to point to whatever the Master git installation is (e.g. c:\apps\git\bin\git.exe), and then configure the custom "Tool Locations" for each node. This way you can run the same jenkins job in different master/slave OS. Steps:

  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 checked 2.3 Click "Add" 2.4 Select "(Git) Default" on the dropdown 2.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 on linux 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.

Community
  • 1
  • 1
L. Holanda
  • 4,432
  • 1
  • 36
  • 44
5

Ensuring "git" in the path of all slaves and master is one good way.

However Jenkins can have multiple installation of git (true for other tools such as jdk, groovy...)

You can configure this from http://server-url/configure

enter image description here

Click on "Add Git" and provide new git with different name and path

enter image description here

You can then "select which git to use" in the "jobs" configuration.

enter image description here

This approach has a positive side effect. It will allow you to use different git client versions (say for testing)

Jayan
  • 18,003
  • 15
  • 89
  • 143
  • Perfect! Thank you Jayan – Steve Folly Feb 07 '16 at 21:40
  • The job have configured runs in a linux box (path to git is /usr/local/bin/git). Master is windows (path to git is git.exe). If I configure the job to use linux-git it runs fine, but Poll SCM fails. If I to use win-git, Poll SCM is fine but job fails. Any ideas? I can find where to configure a Poll SCM specific git. – L. Holanda Mar 05 '16 at 01:48
  • @Leo Holanda : Please ask a new question with more details on your use case. – Jayan Mar 05 '16 at 06:50
  • thx @Jayan, I have asked the new question here: http://stackoverflow.com/questions/35852047 – L. Holanda Mar 07 '16 at 19:17
0

The same environment variable for git dir is fine for that.

unickq
  • 1,497
  • 12
  • 18
0

My issue was Linux master/Windows slave but this could be applicable either way.

The additional behavior Force polling using workspace did the trick for me.

I didn't have the necessary permissions to make the changes in the other solutions. There might be other considerations you need to take before using this behavior so check the plugin docs before implementing.

forceWorkspace

JamesBock
  • 81
  • 7