来自GitLab CI documentation Windows 支持 bash shell。
Supported systems by different shells:
Shells Bash Windows Batch PowerShell
Windows ✓ ✓ (default) ✓
在我的 config.toml 中,我尝试过:
[[runners]]
name = "myTestRunner"
url = xxxxxxxxxxxxxxxxxxx
token = xxxxxxxxxxxxxxxxxx
executor = "shell"
shell = "bash"
但如果我的 .gitlab-ci.yml 尝试执行 bash 脚本,例如
stages:
- Stage1
testJob:
stage: Stage1
when: always
script:
- echo $PWD
tags:
- myTestRunner
然后从包含 GitLab multi runner 的文件夹中右键单击并选择“git bash here”,然后键入:
gitlab-runner.exe exec shell testJob
它无法解析 $PWD
,证明它实际上没有使用 bash 执行器。 (Git bash 通常可以在 Windows 上正确打印出 $PWD
。)
Running with gitlab-runner 10.6.0 (a3543a27)
Using Shell executor...
Running on G0329...
Cloning repository...
Cloning into 'C:/GIT/CI_dev_project/builds/0/project-0'...
done.
Checking out 8cc3343d as bashFromBat...
Skipping Git submodules setup
$ echo $PWD
$PWD
Job succeeded
如果我推送一个提交,也会发生同样的事情,并且基于 Web 的 GitLab CI 终端会自动运行 .gitlab-ci 脚本。
如何在 Windows 上的 GitLab CI 中正确使用 Bash 终端?
最佳答案
首先,我的猜测是它没有正常工作(请参阅问题下方的评论)。我找到了一个解决方法,也许它不是您需要的,但它确实有效。由于某种原因,命令“echo $PWD”在 bash 命令之后连接起来,然后在 Windows cmd 中执行。这就是结果为“$PWD”的原因。要复制它,请在 CMD 控制台中执行以下命令(仅打开 bash):
bash && echo $PWD
解决方案是使用选项 -c 在 bash 中执行命令(这不是理想的解决方案,但它可以工作)。 .gitlab-ci.yml
应该是:
stages:
- Stage1
testJob:
stage: Stage1
when: always
script:
- bash -c "echo $PWD"
tags:
- myTestRunner
关于windows - Gitlab CI : How to use the bash shell on a Windows runner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49625921/