英文:
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/)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论