Search code examples
azureazure-devopsazure-pipelinescommandlet

Azure Pipeline Yaml; file error when initiating a Powershell script


When I am invoking a yaml file in my Azure Pipeline, sample is

 - task: AzurePowerShell@5
      displayName: 'Execute PowerShell Script on Target VMs'
      inputs:
        azureSubscription: ${{ variables.SERVICE_CONNECTION_NAME }}
        pwsh: true
        ScriptType: 'FilePath'
        ScriptPath: 'pipeline-scripts/Deploy-ALZDomainControllers.ps1'
      env:
        LOCATION: $(LOCATION)
        TOP_LEVEL_MG_PREFIX: $(TOP_LEVEL_MG_PREFIX)
        UPSTREAM_RELEASE_VERSION: $(UPSTREAM_RELEASE_VERSION)
        IS_PULL_REQUEST: $(IS_PULL_REQUEST)

I get this error:

##[debug]Caught exception from task script.
##[debug]Error record:
##[debug]The Azure PowerShell version '' specified is not in the correct format. Please check     the format. An example of correct format is 1.0.1
##[debug]At D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\3.236.0\AzurePowerShell.ps1:46 char:5
##[debug]+     throw (Get-VstsLocString -Key InvalidAzurePsVersion -ArgumentList ...
##[debug]+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[debug]    + CategoryInfo          : OperationStopped: (The Azure Power...format is 1.0.1:String) [], RuntimeException
##[debug]    + FullyQualifiedErrorId : The Azure PowerShell version '' specified is not in the correct format. Please check the     format. An example of correct format is 1.0.1
##[debug] 
##[debug]Script stack trace:
##[debug]at <ScriptBlock>, D:\a\_tasks\AzurePowerShell_72a1931b-effb-4d2e-8fd8-f8472a07cb62\3.236.0\AzurePowerShell.ps1: line 46
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]at <ScriptBlock>, <No file>: line 22
##[debug]at <ScriptBlock>, <No file>: line 18
##[debug]at <ScriptBlock>, <No file>: line 1
##[debug]Exception:
##[debug]System.Management.Automation.RuntimeException: The Azure PowerShell version '' specified is not in the correct format. Please check the format. An example of correct format is 1.0.1
##[error]The Azure PowerShell version '' specified is not in the correct format. Please check the format. An example of correct format is 1.0.1
##[debug]Processed: ##vso[task.logissue source=TaskInternal;type=error]The Azure PowerShell version '' specified is not in the correct format. Please check the format. An example of correct format is 1.0.1
##[debug]Processed: ##vso[task.complete result=Failed]

I have no version specification - tried with and withpoot but consistenly the same argument error.

Suggestions please

Have tried using Version with and without quote marks etc but always complains abouyt version.

I want to install and invoke the Azure AZ module and not use the AzureRM module as it is deprecated and some of the commands from Az.Control are what I need to use in my script


Solution

  • Kevin's answer will cover your question. Additionally, use the assistant on the yaml editor (Use task assistant). It will help you to check all the required fields:

    enter image description here