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:
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'
}
As suspected, the issue was with my Jenkins configuration (because everything worked fine locally).
Turns out each sh
line represented a new shell terminal, so all I needed to do was put everything into just one sh
section like so:
steps {
// Create our expected project directory inside our GOPATH's src folder.
// Move our project codes (and its vendor folder) to that folder.
// Build and run tests.
sh '''
mkdir -p ${GOPATH}/src/myproject
mv ${WORKSPACE}/* ${GOPATH}/src/myproject
cd ${GOPATH}/src/myproject
go build
go clean -cache
go test ./... -v -short
'''
}
Many thanks to everyone who helped!