This is a creation in Article, where the information may have evolved or changed.
Hosting go Open source projects on GitHub, CI uses Travis's service to feel very convenient and requires little extra setup, but it involves the company's projects, GITLAB-CI to run Golang project CI, need a bit of skill.
The idea is basically this:
- Create the symbolic link for the catalog in Gopath, point to the working directory Gitlab-runner when CI is executed on the project
- Switch to this linked directory to perform tasks for each stage
The contents of the specific .gitlab-ci.yaml documents are as follows:
before_script: - export GO_PROJECT_NAMESPACE="$GOPATH/src/gitexample.com/$CI_PROJECT_NAMESPACE" - echo $GO_PROJECT_NAMESPACE - mkdir -p $GO_PROJECT_NAMESPACE - ln -srf $(pwd) $GO_PROJECT_NAMESPACE - export GO_PROJECT_PATH="$GO_PROJECT_NAMESPACE/$CI_PROJECT_NAME" - echo $GO_PROJECT_PATH - cd $GO_PROJECT_PATHstages: - build - test - releasebuild: stage: build script: - go build test: stage: test script: - go test -v ./...release: stage: release script: - make goreleaser ...... when: on_success allow_failure: true only: - tags
Here are two questions to note
lncommand must add -f the option to overwrite the previously created link file, to avoid error exit CI.
- The code in the vendor directory of this project has been submitted to the remote repository.
Ref
- GitLab CI Pipeline for Go ($24565) • Snippets GitLab