如何修复AzurePowerShell管道任务中的语法错误?

如何修复AzurePowerShell管道任务中的语法错误?,azure,powershell,azure-devops,azure-pipelines,azure-powershell,Azure,Powershell,Azure Devops,Azure Pipelines,Azure Powershell,我正在尝试使用以下管道任务部署自签名证书: - task: AzurePowerShell@5 inputs: azureSubscription: '${{ parameters.ArmConnection }}' ScriptType: 'InlineScript' azurePowerShellVersion: '2.6.0' Inline: | $Pwd = ConvertTo-SecureString -Strin

我正在尝试使用以下管道任务部署自签名证书:

  - task: AzurePowerShell@5
    inputs:
      azureSubscription: '${{ parameters.ArmConnection }}'
      ScriptType: 'InlineScript'
      azurePowerShellVersion: '2.6.0'
      Inline: |
      $Pwd = ConvertTo-SecureString -String '1234' -Force -AsPlainText
      $Base64 = 'MI..............3000.characters.here............M+wICB9A='
      Import-AzKeyVaultCertificate -VaultName '${{ parameters.resourceGroupName }}''-my-keyvault' -Name ccg-self-signed-cert -CertificateString $Base64 -Password $Pwd
上面列出的3个Powershell命令在Powershell命令提示符下运行良好

但是,当我尝试运行上述管道时,会出现语法错误:

/pipelines/shared.yml:(行:164,列:11,Idx:7111)-(行:164, Col:11,Idx:7111):扫描简单键时,找不到 应为“:”

请问这里发生了什么事

代码为“…”的第164行对于管道脚本来说是否太长

还是我有其他问题

更新:

在缩进内联脚本(谢谢,Mathias!)之后,我遇到了另一个错误,令人惊讶地提到了“主机名”:

-VaultName'${{parameters.resourceGroupName}}'-my keyvault'
是否正确地将RG名称(作为参数传递)前置到字符串“-my keyvault”

更新2:


使用
-VaultName'${{parameters.resourceGroupName}-我的keyvault“
已修复我的问题

我建议选择启用系统诊断并再次运行管道以获取更详细的信息

我建议选择启用系统诊断并再次运行管道以获取更详细的信息

您可能需要缩进内联脚本!这就是为什么错误提到了“键”!是的,我认为解析器可能会将
InlineScript
视为一个空(或单行)列表,并在以下行上查找有效的YAML键。出于某种原因,现在我得到了运行时错误:
##[error]无效URI:无法解析主机名。
即使我的任务中没有明确的主机名或URI。还是Keyvault URI?感谢您在此处分享您的解决方案,请将其转换为答案?因此,它将有助于其他成员谁得到同样的问题,以找到解决方案容易。你可能需要缩进内联脚本啊!这就是为什么错误提到了“键”!是的,我认为解析器可能会将
InlineScript
视为一个空(或单行)列表,并在以下行上查找有效的YAML键。出于某种原因,现在我得到了运行时错误:
##[error]无效URI:无法解析主机名。
即使我的任务中没有明确的主机名或URI。还是Keyvault URI?感谢您在此处分享您的解决方案,请将其转换为答案?因此,它将有助于其他成员谁得到同样的问题,找到解决办法容易。
##[section]Starting: AzurePowerShell
==============================================================================
Task         : Azure PowerShell
Description  : Run a PowerShell script within an Azure environment
Version      : 5.168.1
Author       : Microsoft Corporation
Help         : https://aka.ms/azurepowershelltroubleshooting
==============================================================================
Generating script.
========================== Starting Command Output ===========================
##[command]"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\13d4bf76-87b6-4ac4-9bb5-51ef481420d0.ps1'"
##[command]Import-Module -Name C:\Modules\az_2.6.0\Az.Accounts\1.7.5\Az.Accounts.psd1 -Global
##[command]Clear-AzContext -Scope Process
##[command]Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
##[command]Connect-AzAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
##[command] Set-AzContext -SubscriptionId XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -TenantId ***
##[error]Invalid URI: The hostname could not be parsed.
##[error]PowerShell exited with code '1'.
##[section]Finishing: AzurePowerShell