Edit

Share via


Go install command support in Azure Repos Git

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Go is an open-source programming language, also referred to as Golang. In Go, you can use the install command to download and install packages and dependencies. Azure Repos Git provides support for go install within an Azure Repos Git repository. With go install, you're able to download packages with their dependencies named by the import paths. You can also use the import key word inside a go file to specify the import path, using the same syntax described in the following sections.

Note

The feature documented in this article requires Azure DevOps Server 2019 Update 1 or later version.

Go install with public projects

If your Azure Repos Git repo is in a public project, you can use go install using the web repo url in the following format. For version, you can use latest or a specific version.

go install dev.azure.com/<organization>/<project>/_git/<repo>.git@<version>

You can also install a Go package in a subfolder of a repo by appending the subfolder names, as shown in the following examples.

go install dev.azure.com/<organization>/<project>/_git/<repo>.git/subfolder1@<version>

go install dev.azure.com/<organization>/<project>/_git/<repo>.git/subfolder1/subfolder2@<version>

Go install with private projects

If your Azure DevOps Git repo is private, you can either use SSH or authenticate with a Personal Access Token (PAT) for HTTPS.

Important

To access private Azure Repos Git repositories using go install, you must first set the environment variable GOPRIVATE=dev.azure.com. You can set this environment variable locally before building or running.

SSH

To use SSH with go install, have SSH keys set up for Azure DevOps as described in Use SSH Key authentication.

When you have SSH keys set up, add this entry to your.gitconfig file:

[url "git@ssh.dev.azure.com:v3/<organization>/<project>/<repo>"]
	insteadOf = https://dev.azure.com/<organization>/<project>/<repo>

With this entry and a specific URL format, you can now use go install.

Note

Be sure to use .git after the repo name. Also, _git isn't included in the package URL that you're passing to go install because you're using the SSH URL.

go install dev.azure.com/<organization>/<project>/<repo>.git

HTTPS

To use HTTPS with go install, you must create a PAT as described in Authenticate access with personal access tokens. This PAT requires only the Code (read) scope.

After you create the PAT, add this entry to your.gitconfig file:

[url "https://<user>:<token>@dev.azure.com/<organization>/<project>/_git/<repo>"]
	insteadOf = https://dev.azure.com/<organization>/<project>/_git/<repo>

The <user> part can be any nonempty string; we suggest the word pat.

With this entry and a specific URL format, you can now use go install.

Note

Be sure to use .git after the repo name.

go install dev.azure.com/<organization>/<project>/_git/<repo>.git@<version>

You can also install a Go package in a subfolder of a repo by appending the subfolder names, as shown in the following examples.

go install dev.azure.com/<organization>/<project>/_git/<repo>.git/subfolder1@<version>

go install dev.azure.com/<organization>/<project>/_git/<repo>.git/subfolder1/subfolder2@<version>