[英]How to use go modules in jenkins with private repository?
我正在通過 Jenkins Pipeline 構建一個 go 應用程序,首先我在供應商目錄中添加我所有的 go 依賴項並推送到 VCS,然后在 Jenkins 中構建時提取所有代碼,這很好用。
然后我想遷移到go模塊,因為我在Gitlab中有一個私有的lib依賴項,所以我修改了Jenkins服務器中的netrc文件,正如這個頁面所說: git_https ,並且'go build'在本地機器上完美運行並下載所有依賴項正如預期的那樣,但在 Jenkins 服務器中存在一些問題。 這是我的 Jenkinsfile:
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
中的配置不起作用,我該如何解決這個問題? 感謝您的任何建議。
最好的方法是讓你的項目 ./vendor 目錄成為你的 git 存儲庫。 然后 jenkins build 將使用供應商而不是嘗試從互聯網獲取。 構建命令:
env GO111MODULE=off go build
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.