7

From the GitLab CI documentation the bash shell is supported on Windows.

Supported systems by different shells:
Shells  Bash    Windows Batch   PowerShell
Windows     ✓   ✓ (default)     ✓

In my config.toml, I have tried:

[[runners]]
  name = "myTestRunner"
  url = xxxxxxxxxxxxxxxxxxx
  token = xxxxxxxxxxxxxxxxxx
  executor = "shell"
  shell = "bash"

But if my .gitlab-ci.yml attempts to execute bash script, for example

stages:
  - Stage1 
testJob:
  stage: Stage1
  when: always
  script:
    - echo $PWD  
  tags:
    - myTestRunner

And then from the folder containing the GitLab multi runner I right-click and select 'git bash here' and then type:

gitlab-runner.exe exec shell testJob

It cannot resolve $PWD, proving it is not actually using a bash executor. (Git bash can usually correctly print out $PWD on Windows.)

Running with gitlab-runner 10.6.0 (a3543a27)
Using Shell executor...
Running on G0329...
Cloning repository...
Cloning into 'C:/GIT/CI_dev_project/builds/0/project-0'...
done.
Checking out 8cc3343d as bashFromBat...
Skipping Git submodules setup
$ echo $PWD
$PWD
Job succeeded

The same thing happens if I push a commit, and the web based GitLab CI terminal automatically runs the .gitlab-ci script.

How do I correctly use the Bash terminal in GitLab CI on Windows?

karel
  • 5,489
  • 46
  • 45
  • 50
Blue7
  • 1,750
  • 4
  • 31
  • 55
  • 1
    You should search more SO before actually asking a question. I started to answer that you probably have issues with the windows vs. unix style path the (`/c/gitlab...` style) or it can't be found as you noticed - please check https://stackoverflow.com/questions/41733406/windows-gitlab-ci-runner-using-bash I don't want to repeat what has been already written. – tukan Feb 21 '19 at 10:05
  • As of now, Gitlab's [documentation](https://docs.gitlab.com/runner/executors/#compatibility-chart) says "Bash shell is currently not working on Windows out of the box due to [this issue](https://gitlab.com/gitlab-org/gitlab-runner/-/issues/1515) but is intended to be supported again soon. See the issue for a workaround. " – Gabriel Devillers Apr 12 '22 at 07:25

1 Answers1

2

Firstly my guess is that it is not working as it should (see the comment below your question). I found a workaround, maybe it is not what you need but it works. For some reason the command "echo $PWD" is concatenated after bash command and then it is executed in a Windows cmd. That is why the result is "$PWD". To replicate it execute the following in a CMD console (only bash is open):

bash && echo $PWD

The solution is to execute the command inside bash with option -c (it is not the ideal solution but it works). The .gitlab-ci.yml should be:

stages:
  - Stage1 
testJob:
  stage: Stage1
  when: always
  script:
    - bash -c "echo $PWD"  
  tags:
    - myTestRunner
Carlos Cavero
  • 3,011
  • 5
  • 21
  • 41