Azure 管道 AzurePowerShell@5 失败

Azure Pipeline AzurePowerShell@5 fails

我在 Azure 管道中 运行 AzurePowerShell@5 任务时遇到问题。

我把它归结为这个简单的脚本:

pool:
  vmImage: windows-latest
steps:
- task: AzurePowerShell@5
  inputs:
    azureSubscription: my-azure-sub
    inline: Write-Host "Hello World"
    azurePowerShellVersion: latestVersion
    pwsh: true

... 失败并显示这条有点神秘的消息:

Starting: AzurePowerShell
==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 5.185.0
Author       : Microsoft Corporation
Help         : https://aka.ms/azurepowershelltroubleshooting
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\Program Files\PowerShell\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\adf280e2-5ea5-4fe4-a5b0-5b25afb31371.ps1'"
Added TLS 1.2 in session.
Import-Module -Name C:\Modules\az_6.4.0\Az.Accounts.5.3\Az.Accounts.psd1 -Global
WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
Clear-AzContext -Scope Process
Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
 Set-AzContext -SubscriptionId 7c995cd6-1740-4a31-ae74-d74e61f675e1 -TenantId ***
##[error]The term 'D:\a\s' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
##[error]PowerShell exited with code '1'.
Finishing: AzurePowerShell

不确定我做错了什么?

你不见了ScriptType: 'InlineScript'

steps:
- task: AzurePowerShell@5
  inputs:
    azureSubscription: ''
    ScriptType: 'InlineScript'
    Inline: 'Write-Host "Hello World"'
    azurePowerShellVersion: 'LatestVersion'
    pwsh: true
Starting: AzurePowerShell
==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 5.185.0
Author       : Microsoft Corporation
Help         : https://aka.ms/azurepowershelltroubleshooting
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\Program Files\PowerShell\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp[=11=]0bd73f-ac18-49ee-b670-f1e9fda8d6e5.ps1'"
Added TLS 1.2 in session.
Import-Module -Name C:\Modules\az_6.4.0\Az.Accounts.5.3\Az.Accounts.psd1 -Global
WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
Clear-AzContext -Scope Process
Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
 Set-AzContext -SubscriptionId 26f3dfe8-09e6-475f-b019-06857f15af9f -TenantId ***
Hello World
Finishing: AzurePowerShell