Skip to content

[BUG]: Azure CLI Task2 - ERROR: [WinError 2] The system cannot find the file specified Deploying Bicep Templates #20996

@sgmtg-jcustance

Description

@sgmtg-jcustance

logs_1413.zip

New issue checklist

Task name

AzureCLI@2

Task version

2.254.0

Issue Description

Deploying azure bicep templates using azure cli in Azure Devops yaml pipeline using the AzureCLI@2 task, worked with task version 2.251.1, fails in version 2.254.0
Receive the following error

ERROR: [WinError 2] The system cannot find the file specified

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Azure DevOps Server Version (if applicable)

No response

Operation system

Ubuntu-latest

Relevant log output

Deploying azure bicep templates using azure cli in Azure Devops yaml pipeline using the AzureCLI@2 task, worked with task version 2.251.1, fails in version 2.254.0

Task         : Azure CLI
Description  : Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.
Version      : 2.254.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/azure-cli


Receive the following error during  **az deployment sub create** 

ERROR: [WinError 2] The system cannot find the file specified

Full task logs with system.debug enabled

Details
 [REPLACE THIS WITH YOUR INFORMATION] 

Repro steps

parameters:
- name: azureConnection
  type: string
  default: ''
- name: workload
  type: string
  default: ''
- name: environment
  type: string
  default: ''
- name: instanceId
  type: string
  default: ''
- name: env
  type: string
  default: ''
- name: vmImageName
  type: string
  default: ''
- name: workingDirectory
  type: string
  default: ''
- name: subscriptionId
  type: string
  default: ''
- name: location
  type: string
  default: ''
- name: solutionConfig
  type: string
  default: './solutionConfig/config.json'

steps:
- task: AzureCLI@2
  condition: succeededOrFailed()
  name: deployWorkload${{ parameters.workload }}
  displayName: 'Deploy workload - ${{ parameters.workload }}'
  inputs:
    azureSubscription: ${{ parameters.azureConnection }}
    scriptType: pscore
    scriptLocation: inlineScript
    useGlobalConfig: false
    inlineScript: |
      set-location $(workingDirectory);
      az account set --subscription ${{parameters.subscriptionId}};
      $link = 'https://portal.azure.com/#view/HubsExtension/DeploymentDetailsBlade/~/overview/id/%2Fsubscriptions%2F{0}%2Fproviders%2FMicrosoft.Resources%2Fdeployments%2Fdeploy-ai-{1}-{2}'
      Write-host "$($link -f ${subscriptionId}, ${environment}, ${workload};)" -ForegroundColor Blue;

      az deployment sub create `
        --name 'deploy-aigenie-${{parameters.environment}}-${{parameters.workload}}' `
        --template-file '${{parameters.workload}}/main.bicep' `
        --location '${{parameters.location}}' `
        --parameters '${{parameters.workload}}/main.${{parameters.env}}.bicepparam' `
        -p environment=${{parameters.environment}} `
        -p instanceId=${{parameters.instanceId}};

      $outputs = az deployment sub show `
        --name 'deploy-aigenie-${{parameters.environment}}-${{parameters.workload}}' `
        --query properties.outputs `
        --output json | convertfrom-json;

      if ($outputs) {
        $jsonContent = Get-Content -Path '${{ parameters.solutionConfig }}' | `
          Out-String | ConvertFrom-Json;
        $items = $outputs.psobject.properties | select-object name, value;
        foreach ($item in $items) {
          $jsonContent | Add-member -memberType NoteProperty -name $item.name -value $item.value.value -force;
        }
        $updatedJson = $jsonContent | convertto-json -depth 10;
        $updatedJson | Out-file -filePath '${{ parameters.solutionConfig }}';
      } else { 
        Write-Host "##[warning]$($ENV:WORKLOAD) Deployment produced no outputs.";
        Exit 1;
      }
       

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions