Go (With Modules)

Example Go (With Modules) Pipeline

Example Yaml configuration for a project building a Go binary with Go modules.

Scenario

User is looking to create a pipeline that builds an artifact on any event or branch pushed to source control.

Steps

The following pipeline concepts are being used in the pipeline below:

version: "1"

steps:
  - name: install
    image: golang:latest
    pull: always
    environment:
      CGO_ENABLED: '0'
      GOOS: linux
    commands:
      - go get ./...

  - name: test
    image: golang:latest
    pull: always
    environment:
      CGO_ENABLED: '0'
      GOOS: linux
    commands:
      - go test ./...

  - name: build
    image: golang:latest
    pull: always
    environment:
      CGO_ENABLED: '0'
      GOOS: linux
    commands:
      - go build

Stages

The following pipeline concepts are being used in the pipeline below:

version: "1"

stages:
  install:
    steps:
      - name: install
        image: golang:latest
        pull: always
        environment:
          CGO_ENABLED: '0'
          GOOS: linux
        commands:
          - go get ./...

  test:
    needs: [ install ]
    steps:
      - name: test
        image: golang:latest
        pull: always
        environment:
          CGO_ENABLED: '0'
          GOOS: linux
        commands:
          - go test ./...

  build:
    needs: [ install ]
    steps:
      - name: build
        image: golang:latest
        pull: always
        environment:
          CGO_ENABLED: '0'
          GOOS: linux
        commands:
          - go build