Go

A simple example of a pipeline for a Go project with cross-platform builds.

In the following example, we’re building and testing a project written in Go.

There are two stages — build and test.

image: golang:latest

stages:
  - build
  - test

run unit tests:
  stage: test
  commands:
    - go test -v

run benchmark:
  stage: test
  commands:
    - go test -v -bench=. -benchtime=5s

build for mac:
  stage: build
  variables:
    GOOS: darwin
  commands:
    - go build -v -o output/myapp_$GOOS

build for win:
  stage: build
  variables:
    GOOS: windows
  commands:
    - go build -v -o output/myapp_$GOOS

build for linux:
  stage: build
  variables:
    GOOS: windows
  commands:
    - go build -v -o output/myapp_$GOOS

NOTE: the pipeline could be simplified using the YAML merge function like this:

image: golang:latest

stages:
  - build
  - test

run unit tests:
  stage: test
  commands:
    - go test -v

run benchmark:
  stage: test
  commands:
    - go test -v -bench=. -benchtime=5s

.build: &build
  stage: build
  commands:
    - go build -v -o output/myapp_$GOOS

build for mac:
  <<: *build
  variables:
    GOOS: darwin

build for win:
  <<: *build
  variables:
    GOOS: windows

build for linux:
  <<: *build
  variables:
    GOOS: linux
Last modified October 21, 2020