How to configure Gitlab CI for go language projects

藏色散人
Release: 2021-12-08 15:01:12
forward
2657 people have browsed it

This article is provided by thegolangtutorial column to introduce to you how to configure Gitlab CI in the gol language project. I hope it will be helpful to friends in need!

pipeline process

  • Use golangci-lint to check the code
  • Compile Code
  • Deploy binary

before_script Set environment variables

Main GOPROXY settings

before_script: - echo "before_script" - git version - go env -w GOPRIVATE=code.haiziwang.com - mkdir -p .go - go version - go env -w GO111MODULE=on - go env -w GOPROXY="https://goproxy.io,direct"
Copy after login

golangci-lint

Integrated by default Many out-of-the-box linters

How to configure Gitlab CI for go language projects

https://golangci-lint.run/

golangci-lint: image: golangci/golangci-lint:v1.27.0 stage: lint extends: .go-cache allow_failure: true script: - golangci-lint run -v
Copy after login

allow_failure means that if it fails, you can continue to run subsequent jobs

Compile

compile: stage: build extends: .go-cache script: - go mod download - go build -race -o $OUTPUT_NAME artifacts: paths: - $OUTPUT_NAME
Copy after login

cache go mod

.go-cache: variables: GOPATH: $CI_PROJECT_DIR/.go cache: paths: - .go/pkg/mod/
Copy after login

full example

# This file is a template, and might need editing before it works on your project. image: hub-mirror.c.163.com/library/golang:latest .go-cache: variables: GOPATH: $CI_PROJECT_DIR/.go cache: paths: - .go/pkg/mod/ variables: OUTPUT_NAME: helloworld-app stages: - lint - build - deploy before_script: - echo "before_script" - git version - go env -w GOPRIVATE=code.haiziwang.com - mkdir -p .go - go version - go env -w GO111MODULE=on - go env -w GOPROXY="https://goproxy.io,direct" golangci-lint: image: golangci/golangci-lint:v1.27.0 stage: lint extends: .go-cache allow_failure: true script: - golangci-lint run -v compile: stage: build extends: .go-cache script: - go mod download - go build -race -o $OUTPUT_NAME artifacts: paths: - $OUTPUT_NAME deploy-dev: stage: deploy script: - echo "deploy dev environment"
Copy after login

The above is the detailed content of How to configure Gitlab CI for go language projects. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!