Build and test Go projects
Use a pipeline to automatically build and test your Go projects.
Create your first pipeline
Are you new to Azure Pipelines? If so, then we recommend you try this section before moving on to other sections.
Import this repo into your Git repo:
Sign in to Azure Pipelines
Sign in to Azure Pipelines. After you sign in, your browser goes to
https://dev.azure.com/my-organization-name and displays your Azure DevOps dashboard.
Within your selected organization, create a project. If you don't have any projects in your organization, you see a Create a project to get started screen. Otherwise, select the Create Project button in the upper-right corner of the dashboard.
Create the pipeline
Sign in to your Azure DevOps organization and navigate to your project.
Go to Pipelines, and then select New Pipeline.
Walk through the steps of the wizard by first selecting GitHub as the location of your source code.
If this is not what you see, then make sure the Multi-stage pipelines experience is turned on.
You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.
When the list of repositories appears, select your repository.
You might be redirected to GitHub to install the Azure Pipelines app. If so, select Approve and install.
When the Configure tab appears, select Go.
When your new pipeline appears, take a look at the YAML to see what it does. When you're ready, select Save and run.
You're prompted to commit a new azure-pipelines.yml file to your repository. After you're happy with the message, select Save and run again.
If you want to watch your pipeline in action, select the build job.
You just created and ran a pipeline that we automatically created for you, because your code appeared to be a good match for the Go template.
You now have a working YAML pipeline (
azure-pipelines.yml) in your repository that's ready for you to customize!
When you're ready to make changes to your pipeline, select it in the Pipelines page, and then Edit the
See the sections below to learn some of the more common ways to customize your pipeline.
To make changes to the YAML file as described in this topic, select the pipeline in Pipelines page, and then select Edit to open an editor for the
You can use Azure Pipelines to build your Go projects without needing to set up any infrastructure of your own. You can use Linux, macOS, or Windows agents to run your builds.
Update the following snippet in your
azure-pipelines.yml file to select the appropriate image.
pool: vmImage: 'ubuntu-latest'
Set up Go
Starting with Go 1.11, you no longer need to define a
$GOPATH environment, set up a workspace layout, or use the
dep module. Dependency management is now built-in.
This YAML implements the
go get command to download Go packages and their dependencies. It then uses
go build to generate the content that is published with
trigger: - master pool: vmImage: 'ubuntu-latest' steps: - task: GoTool@0 inputs: version: '1.13.5' - task: Go@0 inputs: command: 'get' arguments: '-d' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: Go@0 inputs: command: 'build' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: CopyFiles@2 inputs: TargetFolder: '$(Build.ArtifactStagingDirectory)' - task: PublishBuildArtifacts@1 inputs: artifactName: drop
go build to build your Go project. Add the following snippet to your
- task: Go@0 inputs: command: 'build' workingDirectory: '$(System.DefaultWorkingDirectory)'
go test to test your go module and its subdirectories (
./...). Add the following snippet to your
- task: Go@0 inputs: command: 'test' arguments: '-v' workingDirectory: '$(modulePath)'
Build an image and push to container registry
Go extension for Visual Studio Code (Microsoft)