14

I want to install a gitlab-runner (executor shaell) on my Windows 10 box. I start the job on the gitlab server and it always ends up with the message the command "git" cannot be found (roughly translated into english). As a matter of fact git is not part of my path. How can I modify my PATH variable for the shell the gitlab-runner starts?

To use git on the command line in windows I usually set it with the statement: PATH %PATH%C:\Program Files\Git\bin.

Is it documented somewhere, git has to be available to the runner? How can I see the command line the runner invokes (i.e. the call to git)?

5 Answers 5

12

This GitLab Runner issue answers your question.

The environment setting doesn't work since it gets evaluated before the variables are set, but you can use pre_build_script in the runner config to update the path.

[[runners]]
  name = "My Runner"
  url = "https://gitlab.com/"
  token = "Abcd1234"
  executor = "shell"
  pre_build_script = "set Path=%GIT_HOME%\\usr\\bin;%Path%"
Sign up to request clarification or add additional context in comments.

1 Comment

Since my runner was using powershell, I had to use pre_build_script = "$Env:PATH += \";C:\\Program Files\\7-Zip\"", but it worked. Thanks.
6

For testing purposes I started the gitlab-runner like: gitlab-runner -l debug --debug run --config config.toml --service gitlab-runner from the directory where the gitlab-runner.exe and the config.toml file reside.

I added the following line to the runners section of my config.toml file:

environment = ['PATH=%PATH%;d:/java/bin;C:/Program Files/Git/bin;c:/program files (x86)/apache-ant-1.10.1/bin']

2 Comments

I tried your solution but I still have the error message : "the command "git" cannot be found"...
It seems the gitlab-runner does the variable expansion using the syntax ${ENV_VAR} even on Windows. However, it also seems that one cannot use the original value of the environment variables. So when setting environment = ['SOME_VALUE=foo','PATH=${PATH};${SOME_VALUE}'], I get the value ;foo for %PATH%. So the variable of SOME_VALUE is expanded as expected but PATH is expanded to an empty value.
0

On macOS the only thing that really worked for me is this solution of adding the PATH to Library/LaunchAgents/gitlab-runner.plist:

<key>EnvironmentVariables</key>
<dict>
    <key>PATH</key>
    <string>/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>

Then restart gitlab-runner and you are good to go.

I suppose there is a Windows equivalent of this solution as well.

1 Comment

It seems Windows lacks this feature: "The service control manager does not support passing custom environment variables to a service at startup. Also, the service control manager does not detect and pass on changes to environment variables as the service is running. Instead of making a service dependent on an environment variable, use registry values or ServiceMain arguments." from learn.microsoft.com/en-us/windows/win32/services/…
0

One can also configure the shell executor environment editing $HOME/.profile (or $HOME.bash_profile) of the gitlab-runner user.

To check the gitlab-runner home directory, run $ sudo cat /etc/passwd | grep gitlab-runner | cut -d: -f6 .

Comments

-1

On Windows 11 I use:

[[runners]]
  name = "win11"
  ...
  environment = ['PATH=%PATH%;C:\Git\cmd']

As my Git installation is under c:\git – adjust this path.

Reference: https://forum.gitlab.com/t/runner-git-not-recognized-windows-11/106053/3

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.