Building Golang Project CI environment based on GITLAB-CI

Source: Internet
Author: User
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:

    1. Create the symbolic link for the catalog in Gopath, point to the working directory Gitlab-runner when CI is executed on the project
    2. 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

    1. lncommand must add -f the option to overwrite the previously created link file, to avoid error exit CI.
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.