【发布时间】:2019-08-15 06:31:32
【问题描述】:
我正在通过 Jenkins 部署一个 Go 应用程序并运行一些测试。
即使我从我的 GOPATH 中删除了所有第三方库,我的所有测试都在本地通过,因为我已经通过 godep save 填充了我的 vendor 文件夹。
但是,当 Jenkins 运行我的测试时,它报告 GitHub 版本和供应商版本之间的类型不兼容:
mypackage/MyFile_test.go:65:22: cannot use MY_VARIABLE
(type "github.com/gocql/gocql".UUID) as type
"myproject/vendor/github.com/gocql/gocql".UUID in assignment
我尝试使用Dep(Go 团队的官方供应商经理)而不是godep,但没有解决问题。
我是否需要告诉我的测试使用“myproject/vendor/github.com/gocql/gocql”而不是“github.com/gocql/gocql”? (更新:显然这是非法的,会报错must be imported as github.com/gocql/gocql。)
我该如何解决这个问题?
更新:
- 我在本地机器和 Jenkins 服务器上都使用 Go 1.12.1。
- 我没有使用任何形式的
go modules。
这是我的 Jenkins 流水线代码的 Go 部分。会不会和这个问题有关?
steps {
// Create our project directory.
sh 'cd ${GOPATH}/src'
sh 'mkdir -p ${GOPATH}/src/myproject'
// Copy all files in our Jenkins workspace to our project directory.
sh 'cp -r ${WORKSPACE}/* ${GOPATH}/src/myproject'
// Copy all files in our "vendor" folder to our "src" folder.
sh 'cp -r ${WORKSPACE}/vendor/* ${GOPATH}/src'
// Build the app.
sh 'go build'
// Remove cached test results.
sh 'go clean -cache'
// Run Unit Tests.
sh 'go test ./... -v -short'
}
【问题讨论】:
-
你使用的是什么版本的 go? Jenkins 和您本地开发的版本是否相同?
-
@Varcorb 我在本地和 Jenkins 服务器上都使用 Go 1.12.1,但我认为这与这个问题没有任何关系,因为它看起来更像是 Go 处理 @987654329 @ 库与非
vendor库不同。鉴于/vendor/是它们名字的唯一区别,Go 不应该足够聪明地知道它们是相同的吗? -
@Varcorb 我假设这是因为如果 Jenkins 在 GOPATH 中找不到第三方库,它只会查看
vendor文件夹。这意味着它应该对vendor和非vendor库一视同仁,不是吗? -
我问的原因是因为 1.12.1 有
go modules功能,可能不是在寻找GOPATH?GO111MODULE环境变量是否设置为on?。 -
@Varcorb 我没有使用
go modules,因为我认为它还没有被广泛使用。我使用的一些第三方库与它不完全兼容,应该没问题,因为我没有在Jenkins中配置Go使用go modules。
标签: go jenkins dependency-management vendor