I am attempting to push a Docker image from Azure Pipelines to an Artifact registry.
When I try to setup a service connection in Azure Pipelines to https://us-west2-docker.pkg.dev/bustling-nomad-434602-q3/gcloud-docker-artifact the fails with an authentication error.
I can push the image using https://gcr.io/bustling-nomad-434602-q3 which then creates a gcr.io repository in my project.
Here are my steps:
gcloud services enable containerregistry.googleapis.com
gcloud services enable artifactregistry.googleapis.com
gcloud iam service-accounts keys create \
azure-pipelines-publisher.json --iam-account $AZURE_PIPELINES_PUBLISHER
tr -d '\n' < azure-pipelines-publisher.json > azure-pipelines-publisher-oneline.json
Hey there 👋
Check JSON Key: Make sure it’s one line, no extra spaces.
Correct Roles: Confirm service account has Artifact Registry Reader/Writer roles.
Correct URL: Use https://us-west2-docker.pkg.dev/[PROJECT-ID]/[REPOSITORY].
Run: docker login -u _json_key -p "$(cat azure-pipelines-publisher-oneline.json)" https://us-west2-docker.pkg.dev
If login works, you’re set. If not, double-check for typos or permission issues. Cheers.
Thanks for your response. The login work so I changed the Azure DevOps service connection to use the https://us-west2-docker.pkg.dev url and the pipeline to use the repository spec bustling-nomad-434602-q3/locations/us-west2/repositories/gcloud-docker-artifact
The result was a different error:
The push refers to repository [us-west2-docker.pkg.dev/bustling-nomad-434602-q3/gcloud-docker-artifact]
943b35739f35: Preparing
...
dacaab4534e4: Waiting
denied: Unauthenticated request. Unauthenticated requests do not have permission "artifactregistry.repositories.uploadArtifacts" on resource "projects/bustling-nomad-434602-q3/locations/us-west2/repositories/gcloud-docker-artifact" (or it may not exist)
##[error]denied: Unauthenticated request. Unauthenticated requests do not have permission "artifactregistry.repositories.uploadArtifacts" on resource "projects/bustling-nomad-434602-q3/locations/us-west2/repositories/gcloud-docker-artifact" (or it may not exist)
##[error]The process '/usr/bin/docker' failed with exit code 1
I verified that the service does have the "artifactregistry.repositories.uploadArtifacts" for the registry:
Hey! Looks like you've got most of it set up correctly, but the auth issue is still a pain. Instead of sticking with the service connection in Azure Pipelines, try switching to using gcloud directly for Docker auth. Here’s what you can do:
1. Add a script step in your pipeline to handle the gcloud auth:
------
- script: |
echo $(serviceAccountKey) > $(Build.SourcesDirectory)/key.json
gcloud auth activate-service-account --key-file=$(Build.SourcesDirectory)/key.json
gcloud auth configure-docker us-west2-docker.pkg.dev --quiet
displayName: 'Authenticate using gcloud'
-----
2. Then, just make sure your Docker task uses that config without messing around with manual docker login:
-------
- task: Docker@2
displayName: 'Build and Push Docker Image'
inputs:
containerRegistry: 'gcrServiceConnection' # Keep this pointing right if you're using the connection
repository: 'gcloud-docker-artifact'
command: 'buildAndPush'
Dockerfile: 'Dockerfile'
tags: '$(Build.BuildNumber)'
------
This should handle the authentication properly without those annoying “unauthenticated request” errors. Give it a shot and let me know if it still acts up! cheers -Kruzing 🤘
User | Count |
---|---|
2 | |
1 | |
1 | |
1 |