简体   繁体   中英

gitlab-ci with Golang do not create the right folder structure

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 ./...

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. Eg

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"

For workaround, you can copy cloned project to GOPATH folder.

    script :
    - mv /builds/ $GOPATH/src/github.com/company/project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM