Search code examples
windowsbashcontinuous-integrationqt5gitlab-ci-runner

Unable to execute a bash script in local windows gitlab runner


Context

I want to run a bash script during the building stage of my CI.

So far, MacOS building works fine and Unix is in progress but I cannot execute the scripts in my Windows building stage.


Runner

We run a local gitlab runner on Windows 10 home where WSL is configured, Bash for Windows installed and working : Bash executing in Windows powershell


Gitlab CI

Here is a small example that highlights the issue.

gitlab-ci.yml

stages:
  - test
  - build

build-test-win:
  stage: build
  tags:
    - runner-qt-windows
  script:
    - ./test.sh

test.sh

#!/bin/bash

echo "test OK"

Job

Running with gitlab-runner 13.4.1 (e95f89a0)
  on runner qt on windows 8KwtBu6r
Resolving secrets 00:00
Preparing the "shell" executor 00:00
Using Shell executor...
Preparing environment 00:01
Running on DESKTOP-5LUC498...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in C:/Gitlab-Ci/builds/8KwtBu6r/0/<company>/projects/player-desktop/.git/
Checking out f8de4545 as 70-pld-demo-player-ecran-player...
Removing .qmake.stash
Removing Makefile
Removing app/
Removing business/
Removing <company>player/
git-lfs/2.11.0 (GitHub; windows amd64; go 1.14.2; git 48b28d97)
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:02
$ ./test.sh
Cleaning up file based variables 00:01
Job succeeded

Issue

As you can see, the echo message "test OK" is not visible in the job output. Nothing seems to be executed but no error is shown and running the script on the Windows device directly works fine.

In case you are wondering, this is a Qt application built via qmake, make and deployed using windeployqt in a bash script (where the issue is).

Any tips or help would be appreciated.

edit : Deploy script contains ~30 lines which would make the gitlab-ci yaml file hard to read if the commands are put directly in the yaml instead of an external shell executed during the CI.

Executing the script from the Windows env


Solution

  • It may be due to gitlab opened a new window to execute bash so stdout not captured.

    You can try use file system based methods to check the execution results, such as echo to files. The artifact can be specified with wildcard for example **/*.zip.

    I also tested on my windows machine. First if i run ./test.sh in powershell, it will prompt dialog to let me select which program to execute. the default is git bash. That means on your machine you may have configured one executable (you'd better find it out)

    I also tried in powershell:

    bash -c "mnt/c/test.sh"
    

    and it gives me test OK as expected, without new window.

    So I suggest you try bash -c "some/path/test.sh" on your gitlab.