简体   繁体   English

用于编译 Go 二进制文件的 Simple.gitlab-ci.yml 文件

[英]Simple .gitlab-ci.yml file for compiling a Go binary

The module name in my go.mod file is gitlab.com/mycorp/mycomp/data/hubpull我的go.mod文件中的模块名称是gitlab.com/mycorp/mycomp/data/hubpull

The 3 files go.mod go.sum main.go are all in the same outermost folder of my project. 3 个文件go.mod go.sum main.go都在我项目的同一个最外层文件夹中。 I have been using these two commands manually on local to compile:我一直在本地手动使用这两个命令进行编译:

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
zip main.zip main

Now I need a gitlab CI file to build a binary based on the above 2 commands.现在我需要一个 gitlab CI 文件来构建基于上述 2 个命令的二进制文件。 I tried searching but a lot of the examples don't work.我试过搜索,但很多例子都不起作用。

Maybe you have already tried it, but this is the best simple build CI file for go.也许您已经尝试过,但这是 go 的最佳简单构建 CI 文件。

image: golang:alpine

stages:
  - build


go_build:
  stage: build
  script:
    - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main main.go
    - zip main.zip main
  artifacts:
    paths:
      - main.zip

There are more you could add like lint, test, etc (refer this -> https://about.gitlab.com/blog/2017/11/27/go-tools-and-gitlab-how-to-do-continuous-integration-like-a-boss/ )您还可以添加更多内容,例如 lint、测试等(请参阅此 -> https://about.gitlab.com/blog/2017/11/27/go-tools-and-gitlab-how-to-do-continuous -像老板一样整合/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何制作一个简单的 GitLab Ci/CD gitlab-ci.yml 文件来构建 Angular 项目? - How to make a simple GitLab Ci/CD gitlab-ci.yml file to build an Angular project? 尝试更新 my.gitlab-ci.yml 文件以运行 SAST 并且管道失败(无法提取图像) - Trying to update my .gitlab-ci.yml file to run SAST and the pipeline fails (Failed to pull image) 是否可以在.gitlab-ci.yml 中使用动态变量? - Is it possible to use dynamic variables in .gitlab-ci.yml? 使用 PWD 在.gitlab-ci.yml 中定义变量时出错 - Error using the PWD to define variables in .gitlab-ci.yml 使用 gitlab-ci.yml 中的 awk 命令杀死 docker 容器 - Kill a docker container using awk command in gitlab-ci.yml 条件 after_script in.gitlab-ci.yml - conditional after_script in .gitlab-ci.yml 如何在 .gitlab-ci.yml 中使用 AWS CLI 和 kubectl - How to use AWS CLI and kubectl in .gitlab-ci.yml 如何在 windows 上使用 gitlab-ci-multi-runner 访问 gitlab-ci.yml 中的变量 - How to access variables in gitlab-ci.yml using gitlab-ci-multi-runner on windows 如何在没有 GitLab Runner 的远程服务器上使用 gitlab-ci.yml 自动部署? - How can i auto deploy with gitlab-ci.yml on a remote server without GitLab Runner? 如何根据.gitlab-ci.yml 中所做的更改跳过工作? - How can I skip a job based on the changes made in .gitlab-ci.yml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM