1

I'm using the GitLab Runner using a shell executor on windows. I'm trying to use bash as the shell for the runner. If I use powershell my script will run but none of the output of the bash scripts is captured. My goal is to use the bash shell so that I can capture the output of my bash scripts and return a fail or success of a job accurately. Changing from powershell to bash as my shell in my config was my first thought.

This is the config.toml of my runner:

concurrent = 1
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "Window's VM"
  url = <gitlab url>
  token = <token>
  executor = "shell"
  shell = "bash"
  builds_dir="/cygdrive/c/Gitlab-Runner/builds/"
  cache_dir="/cygdrive/c/Gitlab-Runner/cache/"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]

I included the builds_dir and cache_dir arguments per this questions answer.

This is the output of my runner when I run the job.

Running with gitlab-runner 15.1.0 (76984217)
  on Window's VM that runs SWEET <token>
Resolving secrets
00:00
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:01
Running on runner0...
Getting source from Git repository
00:00
Fetching changes with git depth set to 50...
error: could not lock config file /cygdrive/c/Gitlab-Runner/builds/<token>/0/repo.tmp/git-template/config: No such file or directory
error: could not lock config file /cygdrive/c/Gitlab-Runner/builds/QxyNx21o/0/repo.tmp/git-template/config: Invalid argument
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit status 1

When I check that file, it exists so I'm unsure of why the runner thinks it doesn't exist.

This is my .gitlab-ci.yml file:

stages:
  - build


run-script:
  stage: build
  tags:
    - sweet
  script:
    - ./script0.sh -s .\another_dir\argument_file
    - ./script1.sh
LukeDev
  • 509
  • 4
  • 19

2 Answers2

1

The solution I found to this was to start the GitLab Runner service with the shell I intended to use. I was used a bash shell to start the service giving it the file system of that shell. This made my /cygdrive/c/paths recognizable to the Runner. You will have to add some arguments to the config telling the runner where certain directories are as it will still look for C:\Gitlab-Runner to find certain files and/or directories. I figured this out reading an answer and it's comments on this question.

LukeDev
  • 509
  • 4
  • 19
0

I know it is late but in case it helps someone: I had the same issue and am using the shell=cmd.exe (yes, I know I need to move this to a more modern shell).

In my case the problem turned out to be that Gitlab-Runner service was running under SYSTEM account which did not have the permissions to the Builds subdirectory, where Runner does the git checkout.

After I've given SYSTEM user all the permissions to the builds subdir it all worked fine, as it was actually able to create the

builds\<token>\0.. 

directory.

Note: I've also tried running Gitlab-Runner under service my interactive login account: it sort of works but confuses the TortoiseGit explorer integration as it stores two sets of authentication data. So before you can successfully use Git from explorer again, you need to clear stored Authentication data. There is probably a way to make Gitlab-Runner running under interactive login account work without these problems, but I have not find one so far ..

Peter
  • 123
  • 1
  • 8