Powershell error " incomplete string token"

64 Views Asked by At

I'm trying to run a workflow file to deploy function app in Azure with new resource group and my workflow yml file fails to run the step and throws an error:

ParserError: D:\a\_temp\2ef5a91f-aee0-4906-9e6e-ab5e5233530f.ps1:3
Line |
   3 |  …  -Name "az-xxx-xxx-rg-businessfuncappxayb" -Location "North Europe" `
     |                                                                          ~
     | Incomplete string token.

YML script:

  name: Resource Group Creation
  uses: azure/powershell@v1
  with:
      azPSVersion: latest
      inlineScript:
        Select-AzSubscription -Subscription ${{ github.event.inputs.businessSubscriptionId }}| `

        New-AzResourceGroup -Name "az-dna-113-rg-businessfuncappxayb" -Location "North Europe" `
      failOnStandardError: $true

YML script:

  name: Resource Group Creation
  uses: azure/powershell@v1
  with:
      azPSVersion: latest
      inlineScript:
        Select-AzSubscription -Subscription ${{ github.event.inputs.businessSubscriptionId }}| `

        New-AzResourceGroup -Name "az-dna-113-rg-businessfuncappxayb" -Location "North Europe" `
      failOnStandardError: $true
1

There are 1 best solutions below

0
Venkat V On BEST ANSWER

The above error suggests there is a syntax issue with your YAML script. It indicates that an incomplete string token exists within your PowerShell script.

You can pass service principal's details in JSON object in a GitHub action and create a secret named AZURE_CREDENTIALS, which you can use to authenticate with Azure.

    {
        "clientId": "<GUID>",
        "clientSecret": "<secret>",
        "subscriptionId": "<GUID>",
        "tenantId": "<GUID>",
        (...)
    }

Here is the YAML script that utilizes PowerShell within the YAML file to create an Azure resource.


    on: [push]
    name: AzureARMSample
    
    jobs:
      build-and-deploy:
        runs-on: ubuntu-latest
        env:
          ResourceGroupName: github-action-arm-rg
          ResourceGroupLocation: "australiaeast"
        steps:
        - uses: actions/checkout@master
        - uses: azure/login@v1
          with:
            creds: ${{ secrets.AZURE_CREDENTIALS }}
            enable-AzPSSession: true
        - uses: Azure/Powershell@v1
          with:
            inlineScript: |
              #!/bin/bash
              New-AzResourceGroup -Name "az-dna-113-rg-businessfuncappxayb" -Location "North Europe"
            azPSVersion: "latest"

The deployment has been successfully completed.

enter image description here

After running the GitHub action, the resource group was created successfully.

enter image description here

Reference: Use the Azure login action with a service principal secret