Go task

Azure Pipelines

Use this task to get, build, or test a go application, or run a custom go command.

YAML snippet

# Go
# Get, build, or test a Go application, or run a custom Go command
- task: Go@0
  inputs:
    #command: 'get' # Options: get, build, test, custom
    #customCommand: # Required when command == Custom
    #arguments: # Optional
    workingDirectory: 

Arguments

Argument Description
command
Command
(Required) Select a Go command to run. Select 'Custom' to use a command not listed here.
Default value: get
customCommand
Custom command
(Required) Custom Go command for execution. For example: to execute go version, enter version.
arguments
Arguments
(Optional) Arguments to the selected command. For example, build time arguments for go build command.
workingDirectory
Working Directory
(Required) Current working directory where the script is run. Empty is the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory)

Example

variables:
  GOBIN:  '$(GOPATH)/bin' # Go binaries path
  GOROOT: '/usr/local/go1.11' # Go installation path
  GOPATH: '$(system.defaultWorkingDirectory)/gopath' # Go workspace path
  modulePath: '$(GOPATH)/src/github.com/$(build.repository.name)' # Path to the module's code

steps:
- task: GoTool@0
  displayName: 'Use Go 1.10'

- task: Go@0
  displayName: 'go get'
  inputs:
    arguments: '-d'

- task: Go@0
  displayName: 'go build'
  inputs:
    command: build
    arguments: '-o "$(System.TeamProject).exe"'

- task: ArchiveFiles@2
  displayName: 'Archive files'
  inputs:
    rootFolderOrFile: '$(Build.Repository.LocalPath)'
    includeRootFolder: False

- task: PublishBuildArtifacts@1
  displayName: 'Publish artifact'
  condition: succeededOrFailed()

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

FAQ