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 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测