如何安装配置window环境的gitlab runner

笔者之前在linux docker环境下安装配置了gitlab及gitlab runner, 但碰到有些程序代码必须得在window环境下构建,这就需要另外安装配置gitlab runner 的window 版本,以下就是

笔者安装配置过程中总结的经验和踩过的坑。

版本 GitLab Community Edition 12.10.3

 

1. 准备一台window server环境,例如 window server 2016 

2. 安装git     https://git-scm.com/download/win

3. 二进制包下载地址 (64位) : https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-windows-amd64.exe

4. 建立一个目录,例如: c:\data\gitlab\, 将二进制包拷贝到这个目录, 并将名称重命名为gitlab-runner

5. 用管理员身份打开一个命令行窗口,进入到二进制包目录

6. 运行命令注册runner

gitlab-runner.exe register

  按照提示分别输入gitlab 服务器的地址和令牌,这个操作和linunx的是一样的,具体可参考我的另外一篇博文 如何安装配置gitlab-runner (区别:  executor 使用 shell )  

 

7. 以服务方式启动gitlab runner

使用内置系统账户启动
gitlab-runner.exe install
gitlab-runner.exe start


使用当前用户账号启动
gitlab-runner.exe install --user ENTER-YOUR-USERNAME --password ENTER-YOUR-PASSWORD
gitlab-runner.exe start

 笔者推荐用后者,这样runner启动所采用的环境变量和当前用户是一致的,这样当在gitlab下构建出现问题时,可以直接用当前账号在window server里测试排查,比较方便,

 如果是用的前者,你也可以后面直接在window 服务的界面里去设置,如图

 

8. 使用.gitlab-ci.yml文件测试自动构建

 

 

 

 

碰到的问题:

1. 在构建前端项目出现错误:Git 签出代码失败,提示 Filename too long

git config --system core.longpaths true

2. 在.gitlab-ci.yml的脚本里bash语法失败

gitlab runner for window默认是用powershell作为命令解释器,   可以手动修改config.toml文件

将shell改成bash, 如下图

注意:要给当前用户的环境变量PATH增加bash的路径,并重启gitlab runner服务,否则会提示找不到bash

如果安装了git,一般会安装bash,路径通常在如下图目录

 

3. 在gitlab pipeline输出页面出现中文乱码,如下图

解决办法:在.gitlab-ci.yml脚本里加上

  before_script:
    - chcp.com 65001


示例:
dotnet_build:
  stage: build
  before_script:
    - chcp.com 65001
  script:
    - dotnet build "web/web.csproj" -c Release

 

4. 在构建的job里如果执行启动web服务不会退出

  如果在job里直接执行web程序, 由于web程序会启动监听服务不会退出,这回导致这个gitlab pipeline的job一直挂着,没法退出。

 解决办法:使用start命令

start //B "command"

示例
start //B "./start.sh"

 

参考:

  https://docs.gitlab.com/runner/install/windows.html

  https://confluence.atlassian.com/bamkb/git-checkouts-fail-on-windows-with-filename-too-long-error-unable-to-create-file-errors-867363792.html

  https://stackoverflow.com/questions/10651975/unicode-utf-8-with-git-bash

   

posted on 2021-03-08 16:50  omage  阅读(370)  评论(2编辑  收藏  举报