Go语言:自动化测试时Jenkins报错build cache is required, but could not be located: GOCACHE is not defined and ne

本文介绍了一种常见的Jenkins执行Go语言构建任务时遇到的环境变量缺失问题,并提供了解决方案,即通过手动设置必要的环境变量来确保构建过程正常进行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 Jenkins执行脚本来运行go的命令时,可能会因为读取不到相关的环境变量而报如下错误,

build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined

解决方案:把go env命令打印出来的环境变量写成export语句加到脚本里,如下所示:

export GO111MODULE=""
export GOARCH="amd64"
export GOBIN=""
export GOCACHE="/root/.cache/go-build"
export GOENV="/root/.config/go/env"
export GOEXE=""
export GOFLAGS=""
export GOHOSTARCH="amd64"
export GOHOSTOS="linux"
export GOINSECURE=""
export GOMODCACHE="/usr/local/go-proj/pkg/mod"
export GONOPROXY=""
export GONOSUMDB=""
export GOOS="linux"
export GOPATH="/usr/local/go-proj"
export GOPRIVATE=""
export GOPROXY="https://mirrors.aliyun.com/goproxy/"
export GOROOT="/usr/local/go"
export GOSUMDB="sum.golang.org"
export GOTMPDIR=""
export GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
export GCCGO="gccgo"
export AR="ar"
export CC="gcc"
export CXX="g++"
export CGO_ENABLED="1"
export GOMOD=""
export CGO_CFLAGS="-g -O2"
export CGO_CPPFLAGS=""
export CGO_CXXFLAGS="-g -O2"
export CGO_FFLAGS="-g -O2"
export CGO_LDFLAGS="-g -O2"
export PKG_CONFIG="pkg-config"
export GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build162435450=/tmp/go-build -gno-record-gcc-switches"

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值