In an Azure DevOps pipeline template, I am declaring a parameter as an array/sequence
parameters:
mySubscription: ''
myArray: []
steps:
- AzureCLI@2
inputs:
azureSubscription: ${{ parameters.mySubscription }}
scriptType: pscore
scriptPath: $(Build.SourcesDirectory)/script.ps1
arguments: '-MyYAMLArgument ${{ parameters.myArray }}'
Value for the parameter is then passed from pipeline definition as
steps:
- template: myTemplate.yml
parameters:
mySubscription: 'azure-connection'
myArray:
- field1: 'a'
field2: 'b'
- field1: 'aa'
field2: 'bb'
My problem is I can't pass that array as-is in YAML syntax (kind of ToString()
) to be able to consume and treat that array from PowerShell in my template. When trying to run this pipeline, I get the following error:
/myTemplate.yml (Line: X, Col: X): Unable to convert from Array to String. Value: Array
. The line/column referenced in the error message correspond to arguments: '-MyYAMLArgument ${{ parameters.myArray }}'
from my template.
I also tried to map the parameter as an environment for my script
- AzureCLI@2
inputs:
azureSubscription: ${{ parameters.mySubscription }}
scriptType: pscore
scriptPath: $(Build.SourcesDirectory)/script.ps1
arguments: '-MyYAMLArgument $Env:MY_ENV_VAR'
env:
MY_ENV_VAR: ${{ parameters.myArray }}
This does not work too:
/myTemplate.yml (Line: X, Col: Y): A sequence was not expected
. That time line/column refers to MY_ENV_VAR: ${{ parameters.myArray }}
.
Does anyone ever faced a similar requirement to pass complex types (here an array/sequence of object) defined from the pipeline definition to a PowerShell script? If so, how did you achieve it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…