Invoking powershell from Devops task:
$workspaceName = 'synwspace-'+$resourceExtension
$datasourceprefix = [string]$datasourceprefix
$datasourceparameter = "{\"data_source\":[\"$datasourceprefix\"]}"
$clientsec = ConvertTo-SecureString -String "$clientSecret" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "$devOpsClientId", $clientsec
$login = az login --service-principal -u "$devOpsClientId" -p "$clientSecret" --tenant "$($tenant)"
az account set -s $subscriptionId
if ($TriggerMasterPipeline -eq $true){
az synapse pipeline create-run --workspace-name $workspaceName --name "P_Landing_to_Enhanced_Master"
}
else{
#az synapse pipeline create-run --workspace-name $workspaceName --name "L_Create_Views" --parameters '{\"data_source\": [\"'+$datasourceprefix+'\"]}'
az synapse pipeline create-run --workspace-name $workspaceName --name "L_Create_Views" --parameters $datasourceparameter
}
I am trying to create a synapse pipeline run using the above command but failing due to parameter input json.
Trying to run Azure cli devops task with powershell script as in the first image, but getting error when passing the json string as parameter input. Any suggestions are appreciated.
Failed to parse string as JSON:
{"data_source": ["++"]}
Error detail: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
The provided JSON string may have been parsed by the shell. See https://docs.microsoft.com/cli/azure/use-cli-effectively#use-quotation-marks-in-arguments
Here is the issue with the JSON parsing, specifically with the value of $datasourceprefix
. The error indicates that it's not correctly interpreted as JSON. So you can use the code below:
$datasourceprefix = "abc"
az synapse pipeline create-run --workspace-name <workspaceName> --name "<pipelineName>" --parameters "{\"data_source\": [\"$datasourceprefix\"]}"
It will run the pipeline successfully as shown below: