Skip to content

Error: 'The system cannot find the file specified' when using az bicep publish in Azure DevOps pipeline with AzureCLI task #31253

Description

@ganeshpenke

Describe the bug

I am trying to publish Bicep modules to an Azure Container Registry (ACR) using az bicep publish within an Azure DevOps pipeline (Windows agent). However, we are encountering the following error:

Image

Related command

az bicep publish --file ${{ parameters.BicepFilePath }} --target br:${{ parameters.ContainerRegistry }}.azurecr.io/bicep/${{ parameters.ModuleName }}:v1

Errors

ERROR: The command failed with an unexpected error. Here is the traceback:
ERROR: [WinError 2] The system cannot find the file specified
Traceback (most recent call last):
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 233, in invoke
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 666, in execute
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 734, in _run_jobs_serially
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 703, in _run_job
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/init.py", line 336, in call
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 120, in handler
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/custom.py", line 4722, in publish_bicep_file
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/_bicep.py", line 226, in bicep_version_greater_than_or_equal_to
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/_bicep.py", line 291, in _get_bicep_installed_version
File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/resource/_bicep.py", line 360, in _run_command
File "subprocess.py", line 548, in run
File "subprocess.py", line 1026, in init
File "subprocess.py", line 1538, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

Issue script & Debug output

  $acrName = "${{ parameters.containerRegistry }}"
  $moduleName = "${{ parameters.ModuleName }}"
  
  Write-Host "Checking if $moduleName exists in ACR..."
  $moduleExists = az acr repository show-tags --name $acrName --repository bicep/$moduleName --query "[?contains(@, 'v1')]" | ConvertFrom-Json

  if ($moduleExists.Count -eq 0) {
    Write-Host "$moduleName not found, publishing..."
    az acr login --name $acrName
    az bicep publish --file ${{ parameters.BicepFilePath }} --target br:${{ parameters.ContainerRegistry }}.azurecr.io/bicep/${{ parameters.ModuleName }}:v1
  } else {
    Write-Host "$moduleName already exists, skipping publish."
  }

Expected behavior

The Bicep module should publish successfully to ACR using az bicep publish.

Environment Summary

azure-cli 2.71.0

core 2.71.0
telemetry 1.1.0

Extensions:
azure-devops 1.0.1

Dependencies:
msal 1.31.2b1
azure-mgmt-resource 23.1.1

Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe'
Config directory 'C:\azureCli'
Extensions directory 'C:\Program Files\Common Files\AzureCliExtensionDirectory'

Additional context

  • Trace shows the failure is during _get_bicep_installed_version which uses _run_command.

  • Might be related to missing bicep.exe on PATH or improper subprocess execution context.

Metadata

Metadata

Assignees

Labels

Auto-AssignAuto assign by botAzure Deploymentsaz deployment/bicep/stack/deployment-scripts/ts/group exportPossible-SolutionService AttentionThis issue is responsible by Azure service team.Similar-Issueact-codegen-extensibility-squadbugThis issue requires a change to an existing behavior in the product in order to be resolved.customer-reportedIssues that are reported by GitHub users external to the Azure organization.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions