gpt4 book ai didi

go - 如何使用适用于 Windows 的 GitLab 管道进行构建

转载 作者:数据小太阳 更新时间:2023-10-29 03:08:35 25 4
gpt4 key购买 nike

我有以下 .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题。

从 Go 1.5 版本开始,交叉编译变得非常容易。

GOOS=windows GOARCH=386 go build -o hello.exe hello.go

您现在可以在 Windows 机器上运行 hello.exe

关于go - 如何使用适用于 Windows 的 GitLab 管道进行构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56664439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com