Gitlab CI 本地Debug

对一个go项目配置gitlab 的ci
配置文件

image: golang:alpine

before_script:
  - go version
  - go env
  - mkdir -p workspace/src/publisher-cmd/
  - mv *.go workspace/src/publisher-cmd/
  - mv vendor workspace/src/publisher-cmd/

build:
  script:
    - export GOPATH=$PWD/workspace  
    - cd workspace/src/publisher-cmd
    - go build -o publisher-cmd_linux
    - GOOS=windows GOARCH=amd64 go build -o publisher-cmd_win
    - GOOS=darwin GOARCH=amd64 go build -o publisher-cmd_mac
    - mv publisher-cmd_linux publisher-cmd_mac publisher-cmd_linux ../../../

  artifacts:
    name: publisher-cmd
    paths:
      - publisher-cmd_linux
      - publisher-cmd_mac
      - publisher-cmd_linux

过程输出

Running with gitlab-ci-multi-runner 1.8.1 (a2efdd4)
Using Docker executor with image golang:alpine ...
Using locally found image version with exactly the same ID
Pulling docker image golang:alpine ...
Running on runner-c8b90077-project-110-concurrent-0 via office...
Cloning repository...
Cloning into '/builds/xi/publisher-cmd'...
Checking out b915dc91 as master...

$ mkdir -p workspace/src/publisher-cmd/
$ mv *.go workspace/src/publisher-cmd/
$ mv vendor workspace/src/publisher-cmd/
$ export GOPATH=$PWD/workspace
$ cd workspace/src/publisher-cmd
$ go build -o publisher-cmd_linux
$ GOOS=windows GOARCH=amd64 go build -o publisher-cmd_win
$ GOOS=darwin GOARCH=amd64 go build -o publisher-cmd_mac
$ mv publisher-cmd_linux publisher-cmd_mac publisher-cmd_linux ../../../
mv: can't rename 'publisher-cmd_linux': No such file or directory
ERROR: Build failed: exit code 1

配置gitlab ci时遇到报错,需要在本地debug,只需要在本地运行 gitlab-runner

安装gitlab-runner Install on macOS - GitLab Documentation

上面的配置中需要跑的job是build

在项目目录里执行

$ gitlab-runner exec docker build

本地更改

build替换成你的job 名字就可以


lidashuang
6.7k 声望165 粉丝

$ Ruby/Elixir/Golang