上下文
我想在CI的构建阶段运行一个bash脚本。
到目前为止,MacOS构建工作正常,Unix正在进行中,但我无法在Windows构建阶段执行脚本。
转轮
我们在配置了WSL的Windows 10家庭上运行本地gitlab runner,安装并运行Bash for Windows:在Windows powershell 中执行Bash
Gitlab CI
下面是一个突出问题的小例子。
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"
作业
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
问题
正如你所看到的,回声消息";测试OK";在作业输出中不可见。似乎没有执行任何操作,但没有显示任何错误,并且在Windows设备上直接运行脚本可以正常工作。
如果您想知道,这是一个通过qmake、make构建的Qt应用程序,并在bash脚本中使用windeployqt进行部署(问题所在(。
如有任何提示或帮助,我们将不胜感激。
编辑:部署脚本包含大约30行,如果命令直接放在yaml中而不是在ci期间执行的外部shell中,这将使gitlab-ci-yaml文件难以读取。
从Windows env 执行脚本
这可能是因为gitlab打开了一个新窗口来执行bash,所以没有捕获stdout。
您可以尝试使用基于文件系统的方法来检查执行结果,例如回显到文件。工件可以用通配符指定,例如**/*.zip
。
我还在我的windows机器上进行了测试。首先,如果我在powershell中运行./test.sh
,它会提示对话框,让我选择要执行的程序。默认值是gitbash。这意味着在你的机器上,你可能已经配置了一个可执行文件(你最好找到它(
我也尝试过powershell:
bash -c "mnt/c/test.sh"
它给了我预期的test OK
,没有新的窗口。
所以我建议你在gitlab上试试bash -c "some/path/test.sh"
。