使用Bash的Windows GitLab CI Runner [英] Windows GitLab CI Runner using Bash

查看:167
本文介绍了使用Bash的Windows GitLab CI Runner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将bash用作Windows上的GitLab CI Runner外壳.

I'm trying to use bash as the shell on Windows for a GitLab CI Runner.

concurrent = 1
check_interval = 0

[[runners]]
  name = "DESKTOP-RQTQ13S"
  url = "https://example.org/ci"
  token = "fooooooooooooooooooobaaaaaaaar"
  executor = "shell"
  shell = "bash"
  [runners.cache]

不幸的是,我找不到选项来指定CI Runner应该使用的实际shell程序.默认情况下,它仅尝试运行找不到的bash.我不知道为什么,因为当我打开Windows命令行并输入bash时,它将起作用.

Unfortunately I can not find an option to specify the actual shell program that the CI Runner should use. By default, it just tries to run bash which it can not find. I don't know why, because when I open up a Windows command line and enter bash it works.

Running with gitlab-ci-multi-runner 1.9.4 (8ce22bd)
Using Shell executor...
ERROR: Build failed (system failure): Failed to start process: exec: "bash": executable file not found in %PATH%

我尝试将文件bash.cmd添加到包含以下内容的用户目录

I tried adding a file bash.cmd to my user directory containing

@"C:\Program Files\Git\usr\bin\bash.exe" -l

这给了我这个奇怪的错误:

That gives me this strange error:

Running with gitlab-ci-multi-runner 1.9.4 (8ce22bd)
Using Shell executor...
Running on DESKTOP-RQTQ13S...
/usr/bin/bash: line 43: /c/Users/niklas/C:/Users/niklas/builds/aeb38de4/0/niklas/ci-test.tmp/GIT_SSL_CAINFO: No such file or directory
ERROR: Build failed: exit status 1

有没有办法正确配置它?

Is there a way to properly configure this?

推荐答案

这里有两个问题,都可能可以解决.

There are two issues going on here, and both can probably be solved.

  1. gitlab-runner找不到bash
  2. gitlab-runner不能很好地结合unix样式和Windows样式的路径.

通过创建bash.cmd文件,您基本上已经成功解决了第一个问题.但是,如果您对为什么没有不能正常运行感到好奇,我想是bash在命令提示符下运行,因为包含它的目录(例如,在您的情况下为"C:\ 用户帐户的"PATH"环境变量中包含"Program Files \ Git \ usr \ bin").但是,也许您正在系统帐户中运行gitlab-runner,该帐户可能没有相同的PATH. 因此,要做的第一件事就是检查系统的PATH变量,并在必要时添加bin目录(例如,按照此处).只需确保在进行更改后就重新启动计算机,因为在重新启动后才应用更改.即使从系统或管理员帐户中运行的服务调用bash,它也应能起作用.

You have essentially succeeded in solving the first one by creating the bash.cmd file. But if you're curious about why it didn't work without it, my guess is that bash runs in your command prompt because the directory that contains it (e.g. in your case "C:\Program Files\Git\usr\bin") is included in the PATH environment variable for your user account. But perhaps you are running the gitlab-runner in the system account, which might not have the same PATH. So the first thing to do is just check your system's PATH variable and add the bin directory if necessary (i.e. using the System applet in the Control Panel as described here or here). Just make sure you restart your machine after you make the change, because the change isn't applied until after you restart. That should make bash work, even when called from a service running in the system or admin account.

关于创建bash.cmd之后遇到的奇怪错误,这是由于第二个问题.结合bash和Windows时,通常通常很难找到正确的路径. Gitlab-runner可能正在尝试确定构建路径是相对的还是绝对的,并最终在Windows路径之前添加它认为是工作目录($PWD)的路径.这看起来像是一个错误,但是gitlab仍未修复它(赛跑者的 9.0 版本!),并且可能永远不会修复.也许他们认为这不是错误,或者是由于底层软件或工具中的错误导致他们无法修复,或者修复起来太困难.无论如何,我发现了一种解决方法.您可以在config.toml文件中指定构建的基本路径.如果您使用unix样式的路径,则可以解决此问题. 在Windows上,config.toml通常与gitlab-runner.exe(或gitlab-multi-runner-amd64.exe等)位于同一文件夹中.在您喜欢的文本编辑器中打开该文件.然后找到[[runners]]部分,并添加类似于以下内容的两行.

As for the strange error you got after creating bash.cmd, that was due to the second issue. Paths are often really hard to get right when combining bash and Windows. Gitlab-runner is probably trying to determine whether the build path is relative or absolute, and ends up prepending the windows path with what it thinks is the working directory ($PWD). This looks like a bug, but gitlab still has not fixed it (as of version 9.0 of the runner!!) and probably never will. Maybe they have decided it is not a bug or that it is due to bugs in underlying software or tools that they can't fix or that it would be too difficult to fix. Anyway, I've discovered a work-around. You can specify the base path for builds in the config.toml file. If you use a unix-style path, it fixes the problem. On windows, config.toml is usually in the same folder as your gitlab-runner.exe (or gitlab-multi-runner-amd64.exe etc). Open that file in your favorite text editor. Then find the [[runners]] section and add two lines similar to the following.

builds_dir="/c/gitlab-runner/builds/"
cache_dir="/c/gitlab-runner/cache/"

您使用的路径应该是您希望gitlab-runner用于存储构建等的任何目录的"bash版本".重要,如果您使用的是cygwin,则应使用与以下类似的路径/cygdrive/c/...而不只是/c/...(适用于msys-git或独立的MSYS2等).

The path you use should be the "bash version" of whatever directory you want gitlab-runner to use for storing builds etc. Importantly if you are using cygwin, you would use a path similar to /cygdrive/c/... instead of just /c/... (which is appropriate for msys-git or standalone MSYS2 etc).

这是config.toml文件的示例:

Here's an example of a config.toml file:

[[runners]]
  name = "windows"
  url = "https://your.server.name"
  token = "YOUR_SECRET_TOKEN"
  executor = "shell"
  shell = "bash"
  builds_dir="/c/gitlab-runner/builds/"
  cache_dir="/c/gitlab-runner/cache/"

这篇关于使用Bash的Windows GitLab CI Runner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆