Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify PATH for gitlab-runner

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)?

like image 540
Bernhard Döbler Avatar asked Sep 15 '17 15:09

Bernhard Döbler


People also ask

Where does GitLab runner execute?

Gitlab Runner is an application that works with GitLab CI/CD to run the job in a pipeline. It is open-source and written in Go Language. It can also be run inside the Docker container or it can be deployed into a Kubernetes cluster.

Does GitLab runner run as root?

Summary. GitLab runner's pwsh shell runs as the root user on linux systems, not gitlab-runner user like the rest of the shell executors.

How do I set environment variables in GitLab?

In GitLab, CI/CD variables can be defined by going to Settings » CI/CD » Variables, or by simply defining them in the . gitlab-ci. yml file. Variables are useful for configuring third-party services for different environments, such as testing , staging , production , etc.


2 Answers

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']

like image 86
Bernhard Döbler Avatar answered Oct 17 '22 08:10

Bernhard Döbler


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%"
like image 4
Dan Avatar answered Oct 17 '22 09:10

Dan