How can i build a docker image from a private git repository (Azure Devops) with the Azure Container Registry

Huf, Tobias 20 Reputation points
2023-05-16T12:35:33.74+00:00

If i am using the Azure Cloud Shell and try to use the acr build task to create a docker image with the command

az acr build -t example__image -f example__docker_file https://******@dev.azure.com/myname/reponame/_git/reponame

i will get the error message:

2023/05/16 09:53:21 Downloading source code... Run ID: cb1t failed after 2s. Error: failed to download context. Please check if the URL is incorrect. If it has credentials, please check if they are expired

But the git credentials in the Cloud Shell (credential manager (store) with using a PAT) are set correctly, because i am able to clone the repository. So how can i pass the git credentials (https) and build the image ?

The actual Cloud Shell i am using:

{
  "azure-cli": "2.48.1",
  "azure-cli-core": "2.48.1",
  "azure-cli-telemetry": "1.0.8",
  "extensions": {
    "ai-examples": "0.2.5",
    "azure-iot": "0.21.0",
    "ml": "2.15.1",
    "ssh": "1.1.6"
  }
}
Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
508 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-05-17T01:03:05.1466667+00:00

    When using the az acr build command to build an image from a remote Git repository, Azure Container Registry needs to authenticate with the Git provider to clone the repository.

    Create a Personal Access Token in Azure DevOps: If you haven't done so already, create a PAT in Azure DevOps. The PAT should have permissions to read the repository.

    https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows

    Use the PAT in the repository URL: When specifying the URL of the Git repository in the az acr build command, include the PAT in the URL. The format should be like this: https://****@dev.azure.com/...**

    az acr build -t example__image -f example__docker_file https://******@dev.azure.com/myname/reponame/_git/reponame
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.