Gitlab CI:如何在Windows运行器上使用bash shell

Blu*_*ue7 5 windows bash gitlab-ci

GitLab CI文档中,Windows支持bash shell.

Supported systems by different shells:
Shells  Bash    Windows Batch   PowerShell
Windows     ?   ? (default)     ?
Run Code Online (Sandbox Code Playgroud)

在我的config.toml中,我尝试过:

[[runners]]
  name = "myTestRunner"
  url = xxxxxxxxxxxxxxxxxxx
  token = xxxxxxxxxxxxxxxxxx
  executor = "shell"
  shell = "bash"
Run Code Online (Sandbox Code Playgroud)

但是,如果我的.gitlab-ci.yml尝试执行bash脚本,例如

stages:
  - Stage1 
testJob:
  stage: Stage1
  when: always
  script:
    - echo $PWD  
  tags:
    - myTestRunner
Run Code Online (Sandbox Code Playgroud)

然后从包含GitLab多跑步者的文件夹中右键单击并选择'git bash here',然后键入:

gitlab-runner.exe exec shell testJob
Run Code Online (Sandbox Code Playgroud)

它无法解决$PWD,证明它实际上并没有使用bash执行程序.(Git bash通常可以$PWD在Windows上正确打印出来.)

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
Run Code Online (Sandbox Code Playgroud)

如果我推送提交,同样的事情发生,基于Web的GitLab CI终端自动运行.gitlab-ci脚本.

如何在Windows上的GitLab CI中正确使用Bash终端?

Car*_*ero 3

首先,我的猜测是它没有按应有的方式工作(请参阅问题下面的评论)。我找到了一个解决方法,也许这不是您需要的,但它有效。由于某种原因,命令“echo $PWD”被连接在 bash 命令之后,然后在 Windows cmd 中执行。这就是为什么结果是“$PWD”。要复制它,请在 CMD 控制台中执行以下命令(仅打开 bash):

bash && echo $PWD
Run Code Online (Sandbox Code Playgroud)

解决方案是在 bash 中使用选项 -c 执行命令(这不是理想的解决方案,但它有效)。应该.gitlab-ci.yml是:

stages:
  - Stage1 
testJob:
  stage: Stage1
  when: always
  script:
    - bash -c "echo $PWD"  
  tags:
    - myTestRunner
Run Code Online (Sandbox Code Playgroud)