How to get GitLab Runner to work with Bash on Windows

Viewed 677

I am trying to setup CI/CD within our GitLab instance to be run on a Windows 10 machine.

I have installed Git for Windows (which includes Git Bash) on the windows system.

I then register the runner according to the instructions given here.

I have then adjusted the config.toml file to use a bash shell, in this manner :

[[runners]]
  name = "DESKTOP-R9R6OV2"
  url = "https://git.mycompany.com/"
  token = "ozaxN3XoJm2sEPzc3BPx"
  executor = "shell"
  shell = "bash"
  builds_dir="/C/Build/"

As per this article - GitLab CI and Git Bash - I have created a bash.cmd file which contains

@"C:\Program Files\Git\usr\bin\bash.exe" -l

I have also ensured that C:\Program Files\Git and C:\Program Files\Git\usr\bin are in the global path definition as the runner is installed in the system admin account.

The pipeline kicks off, but seems to hang :

Running with gitlab-runner 14.7.0 (98daeee0)
  on DESKTOP-R9R6OV2 ozaxN3Xo
Preparing the "shell" executor
Using Shell executor...
Preparing environment

With the process waiting on Preparing environment

I have looked in the Event Viewer logs and there are no messages explaining what is going on.

So my question is, what else do I need to do to get the bash shell to work within GitLab Runner on a Windows 10 system ?

Are there special system permissions which need to be set ?

1 Answers

The working answer to this scenario is to use windows powershell and then launch the git bash shell from there.

So, in your gitlab-ci.yml, add the following powershell commands :

- New-Alias -Name gitBash -Value "$Env:ProgramFiles\Git\bin\bash.exe"
- gitBash -c <name of your bash file>

This will run your bash file within the git bash environment.

This means that your config.toml file must be setup thus :

[[runners]]
    ...
    executor = "shell"
    shell = "powershell"
Related