【问题标题】:Gitlab CI: How to use the bash shell on a Windows runnerGitlab CI:如何在 Windows 运行器上使用 bash shell
【发布时间】:2018-04-03 08:53:24
【问题描述】:

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 多运行器的文件夹中,我右键单击并选择“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 终端?

【问题讨论】:

  • 在实际提问之前,您应该搜索更多 SO。我开始回答您可能对 windows 与 unix 样式路径(/c/gitlab... 样式)有问题,或者您注意到它找不到 - 请检查stackoverflow.com/questions/41733406/… 我不想重复已经发生的事情已经写好了。

标签: windows bash gitlab-ci


【解决方案1】:

首先,我的猜测是它不能正常工作(请参阅问题下方的评论)。我找到了一种解决方法,也许它不是您需要的,但它有效。由于某种原因,命令“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

【讨论】:

  • 效果很好。非常感谢
猜你喜欢
  • 1970-01-01
  • 2016-08-05
  • 1970-01-01
  • 2017-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-23
  • 1970-01-01
相关资源
最近更新 更多