我有以下.gitlab-ci.yml...
stages:
- test
- build
- art
image: golang:1.9.2
variables:
BIN_NAME: example
ARTIFACTS_DIR: artifacts
GO_PROJECT: example
GOPATH: /go
before_script:
- mkdir -p ${GOPATH}/src/${GO_PROJECT}
- mkdir -p ${CI_PROJECT_DIR}/${ARTIFACTS_DIR}
- go get -u github.com/golang/dep/cmd/dep
- cp -r ${CI_PROJECT_DIR}/* ${GOPATH}/src/${GO_PROJECT}/
- cd ${GOPATH}/src/${GO_PROJECT}
test:
stage: test
script:
# Run all tests
go test -run ''
build:
stage: build
script:
# Compile and name the binary as `hello`
- go build -o hello
- pwd
- ls -l hello
# Execute the binary
- ./hello
# Move to gitlab build directory
- mv ./hello ${CI_PROJECT_DIR}
artifacts:
paths:
- ./hello
这适用于 linux,但我现在需要做同样的事情,以便它构建一个 Windows 可执行文件。
然后,我计划运行计划脚本来下载工件。
另一种选择是我在Windows服务器上运行虚拟Linux服务器,并使用它来运行我的go二进制文件。我知道我需要将图像更改为 windows,但无法在线找到合适的图像(为 golang 配置的图像(。
或者是否有可能让这个 docker 镜像构建一个 Windows exe?
这不是一个 gitlab 问题,而是一个去问题。
自 Go 版本 1.5 以来,交叉编译变得非常容易。
GOOS=windows GOARCH=386 go build -o hello.exe hello.go
您现在可以在Windows计算机上运行hello.exe