最近,在 Jenkins 上处理构建时,我在 go get 上遇到了一个问题:尝试构建图像时,Go get 命令会随机失败。 例如,我的 Dockerfile 中有几行:
go get -u golang.org/x/lint/golint && \
go get github.com/glaslos/ssdeep && \
go get github.com/mitchellh/mapstructure && \
go get github.com/denisenkom/go-mssqldb && \
go get -u github.com/go-sql-driver/mysql && \
go get github.com/hashicorp/consul/api && \
go get -u github.com/gin-gonic/gin && \
go get -u github.com/gocql/gocql && \
go get github.com/satori/go.uuid && \
go get github.com/golang/protobuf/protoc-gen-go && \
我会遇到这样的失败:
go get -u github.com/go-sql-driver/mysql cd .; git clone https://github.com/go-sql-driver/mysql /root/go/src/github.com/go-sql-driver/mysql Cloning into '/root/go/src/github.com/go-sql-driver/mysql'... fatal: unable to access 'https://github.com/go-sql-driver/mysql/': Could not resolve host: github.com package github.com/go-sql-driver/mysql: exit status 128
失败的go包是随机分布的。 有谁知道避免这个问题?比如get go package不用go get的工具等等。
非常感谢!
最佳答案
TLDR;只需提交并推送您的 vendor 文件夹即可。
这可能是由网络问题引起的。我的建议是您使用 vendor 解决方案(如 dep 或模块)并将所有依赖项放在 vendor 文件夹中,这样您就可以确保能够复制构建。甚至 Kubernetes ( https://github.com/kubernetes/kubernetes) 在其存储库的 vendor 文件夹中也有其依赖项。
关于在 Jenkins CI 中随机失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52765782/