一个简单的用于编译Go二进制文件的.gitlab-ci.yml文件。

huangapple go评论94阅读模式
英文:

Simple .gitlab-ci.yml file for compiling a Go binary

问题

我的go.mod文件中的模块名称是gitlab.com/mycorp/mycomp/data/hubpull

go.mod go.sum main.go这三个文件都在我项目的最外层文件夹中。我一直在本地手动使用以下两个命令进行编译:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
zip main.zip main

现在我需要一个GitLab CI文件来基于上述两个命令构建一个二进制文件。我尝试搜索,但很多示例都不起作用。

英文:

The module name in my go.mod file is gitlab.com/mycorp/mycomp/data/hubpull

The 3 files go.mod go.sum main.go are all in the same outermost folder of my project. I have been using these two commands manually on local to compile:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
zip main.zip main

Now I need a gitlab CI file to build a binary based on the above 2 commands. I tried searching but a lot of the examples don't work.

答案1

得分: 1

也许你已经尝试过了,但这是用于Go语言的最佳简单构建CI文件。

image: golang:alpine

stages:
  - build

go_build:
  stage: build
  script:
    - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
    - zip main.zip main
  artifacts:
    paths:
      - main.zip

你还可以添加更多内容,比如lint、test等(参考这个链接:https://about.gitlab.com/blog/2017/11/27/go-tools-and-gitlab-how-to-do-continuous-integration-like-a-boss/)。

英文:

Maybe you have already tried it, but this is the best simple build CI file for go.

image: golang:alpine

stages:
  - build


go_build:
  stage: build
  script:
    - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
    - zip main.zip main
  artifacts:
    paths:
	  - main.zip

There are more you could add like lint, test, etc (refer this -> https://about.gitlab.com/blog/2017/11/27/go-tools-and-gitlab-how-to-do-continuous-integration-like-a-boss/)

huangapple
  • 本文由 发表于 2022年9月27日 12:15:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/73862322.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定