windows - Gitlab CI : How to use the bash shell on a Windows runner

标签 windows bash gitlab-ci

来自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/

相关文章:

windows - 构建 64 位 dll 时的警告

c - 测量 CPU 频率 (x86/x64)

windows - 获取图形或显存的API

Python 脚本不会在键盘快捷键上运行

Gitlab CI - Composer 安装在私有(private)仓库上

java - 如何方便终端用户启动Java GUI程序

bash - 在 bash 脚本中按名称查找最大文件

regex - 在 BASH 中使用正则表达式提取数字

python - Gitlab runner Docker 执行器不连接到 postgres 服务

bash - ./deploy.sh 不适用于 gitlab ci