Allow option to change path for cloning in CI
Description
Hello, So I was setting up a pipeline for my go application last weekend, and ran some issues with the GOPATH to build the application and such
Problem
The issue I was having was that the repository was not getting cloned to the correct directory so packages just failed. Now I noticed that it is getting cloned into a specific path Cloning into '/builds/team-name/repo'...
and then when I try to run go build
I start getting the following errors
main.go:3:8: cannot find package "gitlab.com/team-name/agent/agent" in any of:
/usr/local/go/src/gitlab.com/team-name/agent/agent (from $GOROOT)
/go/src/gitlab.com/team-name/agent/agent (from $GOPATH)
Now I get the error of course because the directory structure is not set correctly. For me to fix this issue is that I had to add some scripts in the before_scripts
inside of my .gitlab-ci.yml
like the following
before_script:
- mkdir -p /go/src/gitlab.com/team-name/
- mv ../agent /go/src/gitlab.com/team-name/
- cd /go/src/gitlab.com/team-name/agent
Now doing the above works fine, until it comes to the end of the job, the runner by default cd
back to the /builds/team-name/repo
which understandably gives me the following error. Now I understand the reason it is doing this is to upload the artifacts it generates (speculation)
/bin/bash: line 44: cd: /builds/team-name/repo: No such file or directory
ERROR: Build failed: exit code 1
So in every step, I want to run I have to remember to add the step below
- mv ../agent /builds/team-name/repo
Benefits
Cleaner .gitlab-ci.yml
file
(Include problem, use cases, benefits, and/or goals)
Proposal
Allow the user to change the default location to where the repository getting cloned so for example in my case it clones the repository to /go/src/gitlab.com/team-name/
.
We can use another variable name just like the variable name you use to change the git strategy for example
GIT_LOCATION
or something that reflects what it is doing better
Links / references
My .gitlab-ci.yml
file
image: docker:latest
services:
- docker:dind
before_script:
- mkdir -p /go/src/gitlab.com/team-name/
- mv ../agent /go/src/gitlab.com/team-name/
- cd /go/src/gitlab.com/team-name/agent
stages:
- build
- test
build:
image: digitalrealms/golang-glide:latest
stage: build
script:
- glide install
- go build -v -o app
- mv ../agent /builds/team-name/repo
artifacts:
untracked: true
test:
image: digitalrealms/golang-glide:latest
stage: test
script:
- go test $(glide nv)
- mv ../agent /builds/digital-realms/agent
dependencies:
- build