简体   繁体   English

无法在本地 Windows gitlab runner 中执行 bash 脚本

[英]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.我想在我的 CI 的构建阶段运行一个 bash 脚本。

So far, MacOS building works fine and Unix is in progress but I cannot execute the scripts in my Windows building stage.到目前为止,MacOS 构建工作正常,Unix 正在进行中,但我无法在 Windows 构建阶段执行脚本。


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我们在配置了 WSL 的 Windows 10 home 上运行本地 gitlab 运行程序,安装了 Windows 的 Bash 并正常工作: Bash 在 Windows powershell 中执行


Gitlab CI Gitlab CI

Here is a small example that highlights the issue.这是一个突出问题的小例子。

gitlab-ci.yml 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.如您所见,在作业输出中看不到回显消息“test OK”。 Nothing seems to be executed but no error is shown and running the script on the Windows device directly works fine.似乎没有执行任何操作,但没有显示错误,直接在 Windows 设备上运行脚本可以正常工作。

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).如果您想知道,这是一个通过 qmake 构建的 Qt 应用程序,make 并在 bash 脚本中使用 windeployqt 进行部署(问题出在哪里)。

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.编辑:部署脚本包含约 30 行,如果命令直接放在 yaml 中而不是在 CI 期间执行的外部 shell,这将使 gitlab-ci yaml 文件难以阅读。

Executing the script from the Windows env从 Windows env 执行脚本

It may be due to gitlab opened a new window to execute bash so stdout not captured .可能是因为 gitlab 打开了一个新窗口来执行 bash 所以stdout 没有被捕获

You can try use file system based methods to check the execution results, such as echo to files.您可以尝试使用基于文件系统的方法来检查执行结果,例如 echo to files。 The artifact can be specified with wildcard for example **/*.zip .可以使用通配符指定工件,例如**/*.zip

I also tested on my windows machine.我也在我的 Windows 机器上进行了测试。 First if i run ./test.sh in powershell, it will prompt dialog to let me select which program to execute.首先,如果我在 powershell 中运行./test.sh ,它会提示对话框让我选择要执行的程序。 the default is git bash.默认是 git bash。 That means on your machine you may have configured one executable (you'd better find it out)这意味着在你的机器上你可能已经配置了一个可执行文件(你最好找出来)

I also tried in powershell:我也在powershell中尝试过:

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

and it gives me test OK as expected, without new window.它让我按预期test OK ,没有新窗口。

So I suggest you try bash -c "some/path/test.sh" on your gitlab.所以我建议你在你的 gitlab 上尝试bash -c "some/path/test.sh"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM