Azure Pipeline Yaml;启动 Powershell 脚本时出现文件错误

问题描述 投票:0回答:1

当我在 Azure Pipeline 中调用 yaml 文件时,示例为

 - 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)

我收到此错误:

##[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]

我没有版本规范 - 尝试使用 和 withpoot 但始终出现相同的参数错误。

请提出建议

尝试过使用带引号和不带引号的版本等,但总是抱怨版本。

我想安装并调用 Azure AZ 模块,而不是使用 AzureRM 模块,因为它已弃用,并且我需要在脚本中使用 Az.Control 中的一些命令

azure azure-devops azure-pipelines commandlet
1个回答
0
投票

指定的 Azure PowerShell 版本“”的格式不正确。请检查格式。正确格式的示例是 1.0.1

检查了Azure PowerShell任务定义,问题原因是需要在Azure PowerShell任务中定义

azurePowerShellVersion
preferredAzurePowerShellVersion

例如:

- 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'
        azurePowerShellVersion: 'LatestVersion'
      env:
        LOCATION: $(LOCATION)
        TOP_LEVEL_MG_PREFIX: $(TOP_LEVEL_MG_PREFIX)
        UPSTREAM_RELEASE_VERSION: $(UPSTREAM_RELEASE_VERSION)
        IS_PULL_REQUEST: $(IS_PULL_REQUEST)

或者

- 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'
        preferredAzurePowerShellVersion: '3.1.0'
      env:
        LOCATION: $(LOCATION)
        TOP_LEVEL_MG_PREFIX: $(TOP_LEVEL_MG_PREFIX)
        UPSTREAM_RELEASE_VERSION: $(UPSTREAM_RELEASE_VERSION)
        IS_PULL_REQUEST: $(IS_PULL_REQUEST)

更多详细信息,您可以参考此文档:AzurePowerShell@5 - Azure PowerShell v5 任务

© www.soinside.com 2019 - 2024. All rights reserved.