[英]Azure Pipeline AzurePowerShell@5 fails
I'm having trouble running the AzurePowerShell@5
task in my Azure pipeline.我在 Azure 管道中运行
AzurePowerShell@5
任务时遇到问题。
I have boiled it down to this simple script:我把它归结为这个简单的脚本:
pool:
vmImage: windows-latest
steps:
- task: AzurePowerShell@5
inputs:
azureSubscription: my-azure-sub
inline: Write-Host "Hello World"
azurePowerShellVersion: latestVersion
pwsh: true
... which fails with this somewhat cryptic message: ...失败并显示这条有点神秘的消息:
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\7\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\2.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\1\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
Not sure what I'm doing wrong here?不确定我在这里做错了什么?
You are missing ScriptType: 'InlineScript'
您缺少
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\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\000bd73f-ac18-49ee-b670-f1e9fda8d6e5.ps1'"
Added TLS 1.2 in session.
Import-Module -Name C:\Modules\az_6.4.0\Az.Accounts\2.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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.