First to address your actual error: it seems you are on a windows based runner. That means you have to use windows CMD commands. It does not know ENV, etc.
You can do go env -w GOOS="linux"
instead. Same with GOARCH. Then just run go build .
.
You can also use a variables section to overwrite go env
with environment variables:
variables:
GOOS: "linux"
GOARCH: "amd64"
It goes at the top of the gitlab file somewhere.
Here my typical build pipeline for Go projects using docker containers:
build_App:
image: golang:1.15.3
stage: build
allow_failure: false
tags:
- unix
script:
- go mod download
- mkdir $CI_PROJECT_DIR/release
- cd cmd/app
- GOOS=linux GOARCH=amd64 go build -o $CI_PROJECT_DIR/release/app .
artifacts:
paths:
- $CI_PROJECT_DIR/release
And test pipeline
go_test:
image: golang:1.15.3
stage: verify
allow_failure: false
tags:
- unix
script:
- go mod download
- go test -race -cover ./...
This is based on a runner that uses docker images to build in.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…