【问题标题】:How to use go modules in jenkins with private repository?如何在带有私有存储库的詹金斯中使用 go 模块?
【发布时间】:2019-09-04 02:05:06
【问题描述】:

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

然后我想迁移到 go 模块,因为我在 Gitlab 中有一个私有 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模块构建过程,但是在构建时仍然出现此错误:

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 是我的私有仓库,Jenkins 服务器中netrc 中的配置似乎不起作用,我该如何解决这个问题?感谢您的建议。

【问题讨论】:

    标签: git go jenkins go-modules


    【解决方案1】:

    最好的方法是将您的项目 ./vendor 目录添加到您的 git 存储库。 然后 jenkins 构建将使用供应商,而不是尝试从 intnernet 获取。 构建命令:

    env GO111MODULE=off go build
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 2014-02-28
      • 2019-12-02
      • 2013-04-28
      • 2011-12-15
      相关资源
      最近更新 更多