dongtu0363 2016-08-11 02:21
浏览 155
已采纳

带有Golang的gitlab-ci无法创建正确的文件夹结构

Having a Golang project and Go workspace. I'm trying to run my test, but I'm having the following error :

api/server.go:8:2: cannot find package "github.com/braintree/manners" in any of:
    /usr/local/go/src/github.com/braintree/manners (from $GOROOT)
    /go/src/github.com/braintree/manners (from $GOPATH)

The problem comes from that when cloning the project it does it in this folder :

Cloning into '/builds/compagny/project'...

$GOPATH is /go

and then inside that folder I should have something like : src/github.com/compagny/project

I can : export GOPATH=$(pwd), but that doesn't help, Go expect a /src folder.

But I do not have the control where gitlab-ci clone the project, do I?

my gitlab-ci.yml :

stages:
  - build
  - test

build-my-project:
  image: golang:1.6
  stage: build
  script:
    - go get -u github.com/Masterminds/glide
    - glide install
    - go build

test-my-project:
  image: golang:1.6
  stage: test
  script:
    - go get -u github.com/Masterminds/glide
    - glide install
    - go test -v ./...
  • 写回答

2条回答 默认 最新

  • duandanxiu6965 2016-10-23 04:42
    关注

    Use the go wrapper provided in the image instead of glide. It will create a symlink in the proper location and then go get your dependencies. E.g.

    build-my-project:
      image: golang:1.6
      stage: build
      script:
        - go-wrapper download
        - go build
    

    So the go wrapper knows the proper path of your project you will need to add it as an import comment in your main.go like so:

    package main // import "github.com/your/repo"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看