简体   繁体   中英

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.

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 ':'.

截图错误

What is happening here please?

Is the line 164 with the code $Base64 = '.....' too long for a pipeline script?

Or do I have some other issue?

UPDATE:

After indenting the inline script (thanks, Mathias,), I get another error: surprisingly talking about a "hostname":

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

UPDATE 2:

Using -VaultName '${{ parameters.resourceGroupName }}-my-keyvault' has fixed my problem

I would advise on selecting enable system diagnostic and run pipeline one more to get more detailed info

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM