gpt4 book ai didi

git - 如何在带有私有(private)存储库的 Jenkins 中使用 go 模块?

转载 作者:行者123 更新时间:2023-12-03 10:01:55 28 4
gpt4 key购买 nike

我正在通过 Jenkins Pipeline 构建一个 go 应用程序,首先我将所有 go 依赖项添加到 vendor 目录中并推送到 VCS,然后在 Jenkins 中构建时提取所有代码,这工作正常。

然后我想迁移到 go 模块,因为我在 Gitlab 中有一个私有(private) lib 依赖项,所以我修改了 Jenkins 服务器中的 netrc 文件,因为这个页面说:git_https ,并且'go build'在本地机器上完美运行并按预期下载所有依赖项,但在Jenkins服务器中存在一些问题。
这是我的 Jenkins 文件:

pipeline {
agent any

stages {

stage('build') {
agent {
docker { image 'golang:1.12' }
}

steps {

sh "export XDG_CACHE_HOME=/tmp/.cache \
&& go build"
}
}

}
}

如代码所示,我使用“go build”来触发 go module 构建过程,但在构建时仍然出现此错误:
go get gitlab.com/gbuda/dblib: git ls-remote -q origin in /go/pkg/mod/cache/vcs/a8fb1674af641945219afa3eee63923c22afe0df48bc030a6bf714abb7116332: exit status 128:
fatal: could not read Username for 'https://gitlab.com': terminal prompts disabled
If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
gitlab.com/gbuda/dblib是我的私有(private)存储库,似乎是 netrc 中的配置在 Jenkins 服务器中没有工作,我该如何解决这个问题?感谢您的任何建议。

最佳答案

最好的方法是将您的项目 ./vendor 目录添加到您的 git 存储库。
然后 Jenkins 构建将使用 vendor 而不是尝试从互联网上获取。
构建命令:

env GO111MODULE=off go build

关于git - 如何在带有私有(private)存储库的 Jenkins 中使用 go 模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55666333/

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