ADF pipeline generated PrePostDeployment script with a "?" on stopping trigger

Michelle Sanford 30 Reputation points
2023-01-18T22:15:19.3166667+00:00

We use the node.js packages via YAML script to generate the ARM Templates for ADF deployment. Something has changed with the generation of the PrePostDeployment script which is what is used to start and stop the ADF triggers. The following lines have been added (noted by **). The Power Shell script does not understand what to do with the "?". I haven't changed anything. I don't know if the parameters have changed? If the package.json file needs to change? My YAML file and package.json items look like the sample in [https://learn.microsoft.com/en-us/azure/data-factory/continuous-integration-delivery-improvements (with the real values in YAML of course). Again this worked before the new year. I am hoping someone has seen this and can help. Thanks!

function Update-TriggerTemplate {
    param(
        [string]$templateJson,
        [PSCustomObject]$templateParameters
    )
    $parameterMatches = [System.Text.RegularExpressions.Regex]::Matches($templateJson, '\[parameters\([^)]*\)\]')
    foreach ($parameterMatch in $parameterMatches) {
        $parameterName = $parameterMatch.Value.Substring(13, $parameterMatch.Value.Length - 16)
        if ($null -ne $templateParameters.$($parameterName)) {
            **$parameterType = $templateParameters.$($parameterName).value ? $templateParameters.$($parameterName).value.GetType().Name : $null
            if ($parameterType -eq 'Object[]') {
                $parameterValue = ConvertTo-Json $templateParameters.$($parameterName).value
                $templateJson = $templateJson -replace [System.Text.RegularExpressions.Regex]::Escape("`"$($parameterMatch.Value)`""), $parameterValue
            } elseif ($parameterType -eq 'Boolean' -or $parameterType -eq 'Int64') {
                $templateJson = $templateJson -replace [System.Text.RegularExpressions.Regex]::Escape("`"$($parameterMatch.Value)`""), $templateParameters.$($parameterName).value
            } else {**
                $templateJson = $templateJson -replace [System.Text.RegularExpressions.Regex]::Escape($parameterMatch.Value), $templateParameters.$($parameterName).value
            }
        }
    }

    return $templateJson
}
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} vote

Accepted answer
  1. Kolundzic, Branko 80 Reputation points
    2023-01-19T19:06:51.5266667+00:00

    Did you try to update PowerShell deployment task to use PowerShell Core instead of Windows PowerShell?

                  - task: AzurePowerShell@5
                    displayName: 'Azure PowerShell script: pre deployment'
                    inputs:
                      azureSubscription: '<azure subscription>'
                      ScriptPath: '$(Pipeline.Workspace)/datafactory/application/PrePostDeploymentScript.ps1'
                      ScriptArguments: '<script arguments>'
                      azurePowerShellVersion: LatestVersion
                      pwsh: true   #this property needs to be used to install and use PowerShell Core 7.x version
    
    

    It appears that the latest version of the script is using some PowerShell features available in PowerShell Core. You are probably getting a warning in your pipeline logs that the script is not compatible with the current version of PowerShell.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.