2

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

Aeith
  • 23
  • 1
  • 5
  • why use windows runner, any specific requirement? – Lei Yang Jun 28 '21 at 08:36
  • not really, we have a computer with windows installed so we put gitlab runner here to start building during CI. what do you recommand ? Docker / cross building ? – Aeith Jun 28 '21 at 09:10
  • `sh` is a unix thing, have you tried those commands/scripts on windows? – Lei Yang Jun 28 '21 at 09:11
  • Until we find a solution to this problem, we run all the commands in the yaml file directly which looks hideous and makes the file harder to read and maintain. As said in the post, we installed WSL and Bash for Windows to run bash commands in powershell as shown in the first image linked. The temporary solution mentioned before works and running the script manually in the Windows env does the same but I cannot make it work from the CI yaml file. – Aeith Jun 28 '21 at 09:19
  • I cannot open that image(due to network issue). do i understand correctly, you manually verified that script on windows within `WSL` but not by `cmd`? – Lei Yang Jun 28 '21 at 09:24
  • Yes. I ran the script using `.\test.sh` in : - bash from powershell / cmd - powershell directly (which opens a new window to run the file) I may be wrong but I don't see the point in running bash commands in `cmd` as gitlab runner runs bash from the powershell (default shell specified in the conf.toml). To answer your question : yes in WSL, tried in cmd but it gave me an error ìs not recognized as an internal or external command, operable program or batch file`. PS : Sorry I cannot include images in the post as I require more reputation. – Aeith Jun 28 '21 at 09:32
  • which open a new window --- i suspect this is the difference from linux bash. the gitlab probably don't record output of new window. to prove your script actually ran, you can try such as copy a file, delete a file etc, instead of checking the echo output. – Lei Yang Jun 28 '21 at 09:35
  • I was also suspecting it and it works indeed, nothing is shown in the job output but the folders are created. The only thing is, do you think it also impacts gitlab runner's artifacts retrieval ? My original scripts generates a .zip file which is not found later and thus, cannot be downloaded (but exists in the building directory in the local env). – Aeith Jun 28 '21 at 09:45
  • i think the files can be generated. – Lei Yang Jun 28 '21 at 09:46
  • Indeed. Though, the artifact cannot be retrieved (unable to find the file). It may be related to the file name and/or path, I will check that. Can you post an answer so I can mark this post as solved please? Thanks for your time. – Aeith Jun 28 '21 at 09:54
  • i've posted an answer. – Lei Yang Jun 28 '21 at 11:51

1 Answers1

0

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.

Lei Yang
  • 3,970
  • 6
  • 38
  • 59
  • What use is the flag `-c` *here*? – greybeard Jun 28 '21 at 17:02
  • it's hard to explain for me, but usage is anywhere: [bash(1) — Linux manual page](https://man7.org/linux/man-pages/man1/bash.1.html) – Lei Yang Jun 29 '21 at 00:44
  • Straight from the page you hyperlinked: `If arguments remain after option processing, and [the -c option has not] been supplied, the first argument is assumed to be the name of a file containing shell commands.`: leaving out the "command-string flag" was equivalent to a string commanding the shell to `source` *file*: `-c ". mnt/c/test.sh"`. There is a run time overhead to specifying `-c`, but not `.`. – greybeard Jun 29 '21 at 03:38
  • on my Windows 10 Pro VM, entering `bash` in a PowerShell terminal starts the Linux subsystem for Windows, aka an Ubuntu VM, which is not Windows. – antoine Nov 05 '21 at 18:14