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"

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐