I am deploying a Go application via Jenkins and running some tests.
All my tests pass locally even if I remove all third-party libraries from my GOPATH because I have populated my vendor
folder via godep save
.
However, when Jenkins runs my tests, it reports type incompatibilities between the GitHub version and vendor version:
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
I have tried using Dep
(the Go team's official vendor manager) instead of godep
but it did not resolve the issue.
Do I need to tell my tests to use "myproject/vendor/github.com/gocql/gocql" instead of "github.com/gocql/gocql"? (UPDATE: Apparently this is illegal and will give the error must be imported as github.com/gocql/gocql
.)
How do I solve this?
UPDATES:
- I'm using Go 1.12.1 both on my local machine and Jenkins server.
- I am not using
go modules
of any kind.
Here is the Go section of my Jenkins Pipeline code. Could it have something to with this issue?
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'
}