简体   繁体   English

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

[英]How to fix the syntax error in AzurePowerShell pipeline task?

I am trying to deploy a self-signed certificate by using the following pipeline task:我正在尝试使用以下管道任务部署自签名证书:

  - 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

The 3 Powershell commands listed above work well for me at the PowerShell command prompt.上面列出的 3 个 Powershell 命令在 PowerShell 命令提示符下对我来说效果很好。

But when I try run the above pipeline, I get the syntax error:但是当我尝试运行上面的管道时,我得到了语法错误:

/pipelines/shared.yml: (Line: 164, Col: 11, Idx: 7111) - (Line: 164, Col: 11, Idx: 7111): While scanning a simple key, could not find expected ':'. /pipelines/shared.yml: (Line: 164, Col: 11, Idx: 7111) - (Line: 164, Col: 11, Idx: 7111): 扫描简单密钥时,找不到预期的“:”。

截图错误

What is happening here please?请问这里发生了什么?

Is the line 164 with the code $Base64 = '.....' too long for a pipeline script?带有代码$Base64 = '.....'的第 164 行对于管道脚本来说是否太长?

Or do I have some other issue?还是我有其他问题?

UPDATE:更新:

After indenting the inline script (thanks, Mathias,), I get another error: surprisingly talking about a "hostname":缩进内联脚本后(感谢 Mathias),我得到另一个错误:令人惊讶地谈论“主机名”:

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

Is -VaultName '${{ parameters.resourceGroupName }}''-my-keyvault' a correct way to prepend RG name (passed as param) to the string "-my-keyvault"? -VaultName '${{ parameters.resourceGroupName }}''-my-keyvault'是将 RG 名称(作为参数传递)添加到字符串“-my-keyvault”的正确方法吗?

UPDATE 2:更新 2:

Using -VaultName '${{ parameters.resourceGroupName }}-my-keyvault' has fixed my problem使用-VaultName '${{ parameters.resourceGroupName }}-my-keyvault'解决了我的问题

I would advise on selecting enable system diagnostic and run pipeline one more to get more detailed info我建议选择启用系统诊断并再次运行管道以获得更详细的信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AzurePowerShell 任务找不到文件路径 - AzurePowerShell task cannot find filePath AzurePowershell 任务找不到 Profile.ps1 - AzurePowershell Task Cannot Find Profile.ps1 AzurePowerShell@4 - 无法在 azure 管道上执行 powershell 命令 - AzurePowerShell@4 - powershell commands fail to execute on azure pipeline 通过 Azure DevOps AzurePowershell@5 任务创建新容器的问题 - Issue with Creating New Container Through Azure DevOps AzurePowershell@5 Task azure 使用 resharper 任务构建管道错误 - azure build pipeline error using resharper task 发布于Azure:Mismatch dependency错误。 是什么导致了它以及如何在通过管道使用发布时修复它? - Publish in Azure: Mismatch dependency error. What is causing it and how to fix it when using publishing via a pipeline? 得到'一个任务丢失。 管道引用了一个名为“缓存”的任务。 Azure 管道中的错误 - Getting 'A task is missing. The pipeline references a task called 'Cache'.' error in Azure Pipeline 如何在另一个任务 Azure Pipeline 中重用任务中的 DownloadFile - How to reuse DownloadFile from a task in another task Azure Pipeline 如何获取特定任务的 Azure 管道任务状态? - How to get Azure pipeline Task Status for a specific task? 从 azure devops 管道任务执行 git 克隆时出错 - Error performing git clone from azure devops pipeline task
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM