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.
CodePudding user response:
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/)