In our previous blog post - Manage Go dependencies using Glide, we have a simple Go project to demonstrate dependency management using Glide. Let’s move forward to build the project on GitLab CI.
Before we start
I have created a new project under $GOPATH and copy the all the files from the glide-example. That includes:
- .gitignore
- glide.lock
- glide.yaml
- README.md (optional)
- vendor/
Make sure they could be built and run locally.
Setup the pipeline
Let’s start with adding the following pipeline file to the project root folder.
.gitlab-ci.yaml
|
|
Commit and push this new .gitlab-ci.yaml file to gitlab. Then check the pipeline job.
The error indicates that the build could not locate the vendor package. This is because the checkout project path of the GitLab CI job is /builds/ykyuen/gitlab-ci-go-build which is not under $GOPATH.
The solution
In order to fix the build error, we have to make sure the project is under $GOPATH. This could be done by creating a symbolic link before starting the build process. Let’s update the .gitlab-ci.yaml.
.gitlab-ci.yaml
|
|
Commit and push the change and try the pipeline job again.
Summary
- Go project should be always under $GOPATH.
- Checkin the vendor folder could simplify the pipeline as we do not need to run the glide install command.