Private Go Modules on Azure DevOps

Using a Personal Access Token

git config --global url."https://anythinggoeshere:$devops_token@dev.azure.com".insteadOf "https://dev.azure.com"
go get -v dev.azure.com/${ORG}/${PROJECT}/_git/${REPO}.git
FROM golang:1.12-alpine3.10 AS builderRUN apk add --no-cache git bashWORKDIR /codeARG devops_token
RUN git config --global url."https://anythinggoeshere:$devops_token@dev.azure.com".insteadOf "https://dev.azure.com"
COPY go.mod go.sum ./RUN go mod downloadCOPY . .RUN go build -o main .RUN rm $HOME/.gitconfig
docker build \
-t $IMAGE:$TAG \
--build-arg devops_token=$DEVOPS_TOKEN \
.
VAULT_NAME ?= "NAME-OF-YOUR-VAULT"
DEVOPS_TOKEN_SECRET_NAME ?= "devops-repo-pat"
set-git-redirect:
@token=`az keyvault secret show --name $(DEVOPS_TOKEN_SECRET_NAME) --vault-name $(VAULT_NAME) --query value -o tsv`; \
[ -z "$$token" ] && echo "failed to fetch token..." && exit 1; \
git config --global --unset $(git config --global --get-regexp "dev.azure.com") &>/dev/null || "true" ; \
git config --global url."https://anything:$$token@dev.azure.com".insteadOf "https://dev.azure.com"
https://myorg@dev.azure.com/myorg/myproject/_git/myrepo
# has the SSH equivalent
git@ssh.dev.azure.com:v3/myorg/myproject/myrepo.git
git config --global url."git@ssh.dev.azure.com:v3".insteadOf https://dev.azure.com
go mod init dev.azure.com/myorganization/myproject/mypackage.git
go get -v -u dev.azure.com/myorganization/myproject/mypackage.git
package mainimport (
hello "dev.azure.com/myorganization/myproject/mypackage.git/pkg/hello"
)
func main() {
hello.SayHello()
}

--

--

Software Engineer @ Securitas Intelligent Products

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store