在 Gitlab CI 中,我需要指定GITLAB_DEPLOY_TOKEN
,因为我有一些私有存储库。这适用于编译步骤。
但是当我执行 golint 时,它会再次下载所有依赖项,并且它会在私有依赖项上失败。我可以添加相同的git config
指令,
图片:golang 变量:PACKAGE_PATH:/go/src/gitlab.com/company/sam/daemon PACKAGE_API_NAME:registry.gitlab.com/company/sam/daemon REGISTRY_URL:https ://registry.gitlab.com DOCKER_DRIVER:覆盖 GO111MODULE: “上”
.anchors: - &inject-gopath mkdir -p $(dirname ${PACKAGE_PATH}) && ln -s ${CI_PROJECT_DIR} ${PACKAGE_PATH} && cd ${PACKAGE_PATH}
compile:
stage: build
before_script:
- *inject-gopath
- git config --global url."https://oauth:${GITLAB_DEPLOY_TOKEN}@gitlab.com".insteadOf https://gitlab.com
- go mod tidy
script: GOOS=linux GOARCH=arm GOARM=7 go build -o release/daemon .
artifacts:
name: "binary-$CI_PIPELINE_ID"
paths:
- $GOPATH/pkg/mod/
expire_in: 1 hour
lint:
stage: test
before_script:
- apt install -y curl git
- go get github.com/golang/lint
- *inject-gopath
script:
- $GOPATH/bin/golint -set_exit_status $(go list ./...)
allow_failure: true
我在这里读到go 模块被缓存,$GOPATH/pkg/mod
但它似乎不起作用
知道我应该如何解决它吗?