这篇文章主要讲解了“golang语言项目是如何配置Gitlab CI的”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“golang语言项目是如何配置Gitlab CI的”吧!
pipeline流程
使用golangci-lint 检查代码
编译代码
部署二进制
before_script 设置环境变量
主要 GOPROXY设置
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
默认集成了很多开箱即用的linter
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
allow_failure 表示失败了可以继续跑后续的job
编译
compile: stage: build extends: .go-cache script: - go mod download - go build -race -o $OUTPUT_NAME artifacts: paths: - $OUTPUT_NAME
缓存 go mod
.go-cache: variables: GOPATH: $CI_PROJECT_DIR/.go cache: paths: - .go/pkg/mod/
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-appstages: - lint - build - deploybefore_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 -vcompile: stage: build extends: .go-cache script: - go mod download - go build -race -o $OUTPUT_NAME artifacts: paths: - $OUTPUT_NAMEdeploy-dev: stage: deploy script: - echo "deploy dev environment"
感谢各位的阅读,以上就是“golang语言项目是如何配置Gitlab CI的”的内容了,经过本文的学习后,相信大家对golang语言项目是如何配置Gitlab CI的这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!