Azure / Azure/azure-cli

az acr build fails when using --build-arg, but works without it

Open
#31,071 7 comments 0 reactions 1 assignee Assigned to @leodewang View on GitHub
act-observability-squad Auto-Assign bug Container Registry customer-reported Possible-Solution Service Attention Similar-Issue
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

### Describe the bug

I am using az acr build in a GitHub Actions workflow to build and push a Docker image to Azure Container Registry (ACR).

The following command works fine:
```shell
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} \
--registry ${{ env.AZURE_CONTAINER_REGISTRY }} \
-g ${{ env.ACR_RESOURCE_GROUP }} \
-f ${{ env.DOCKER_FILE }} \
${{ env.BUILD_CONTEXT_PATH }}
```

### Related command
But this command gives us the error as shown in the screenshot
```shell
az acr build --image ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_NAME }}:${{ github.sha }} \
--registry ${{ env.AZURE_CONTAINER_REGISTRY }} \
-g ${{ env.ACR_RESOURCE_GROUP }} \
-f ${{ env.DOCKER_FILE }} \
--build-arg AZURE_COMMUNICATION_SERVICES_CONNECTION_STRING=${{ secrets.AZURE_COMMUNICATION_SERVICES_CONNECTION_STRING }} \
--build-arg AZURE_COMMUNICATION_SENDER_EMAIL=${{ secrets.AZURE_COMMUNICATION_SENDER_EMAIL }} \
--build-arg AZURE_COMMUNICATION_RECIPIENT_EMAIL=${{ secrets.AZURE_COMMUNICATION_RECIPIENT_EMAIL }} \
${{ env.BUILD_CONTEXT_PATH }}
```
![Image](https://github.com/user-attachments/assets/dd43ed70-e960-407b-bd53-08ecd410e508)

### Errors

However, when I add --build-arg options, the command fails with the error:
"the following arguments are required: "

### Expected behavior

Both versions of the command should work as expected. Adding --build-arg should not break the az acr build command.

Actual Behavior:
Adding --build-arg results in the following error:
`ERROR: the following arguments are required: `

### Additional context

I confirmed that the Dockerfile and build context exist
The same command works locally, but fails in GitHub Actions
Possible issue with how az acr build handles --build-arg in GitHub Actions?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.