dongsi8812 2019-03-25 02:46
浏览 117
已采纳

与供应商文件夹的类型不兼容

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'    
}
  • 写回答

1条回答 默认 最新

  • douhushen3241 2019-03-25 06:02
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 flask项目,怎么使用AJAX传数据库数据到echarts图表的data里,实现异步加载数据。
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题