microsoft / azure-pipelines-yaml

Azure Pipelines YAML examples, templates, and community interaction
MIT License
1.19k stars 924 forks source link

It is possible to convert a json to variables/parameters YAML and iterate? #599

Closed giseliramos closed 3 months ago

giseliramos commented 10 months ago

Hello,

I have a powershell script in a stage that creates a jsonObject and I save it to a variable to be reused later:

$imagesJson = @"
[
{
   "myAcr": "someCustomAcr1",
   "listImages": "image1, image2"
},
{
   "myAcr": "someCustomAcr2",
   "listImages": "image4, image5, image6"
}
]
"@

# < some operations I do on imagesObj, already converted >

$newJson = ConvertTo-Json $imagesObj -Compress
"##vso[task.setvariable variable=ImagesList;isOutput=true]$newJson"

This part works okay. The matter is that I want to populate some YAML variables with it or iterate, for example, I want to iterate for each "dict" here and extract the info. Is that possible to do in the YAML, to populate on variables or on parameters template?

Thanks!

KonstantinTyukalov commented 10 months ago

Hi @giseliramos, because these are runtime pipeline variables, you can't use YAML template syntax (which is compile-time) with them. More info about runtime(+macro) and compile variables and differences between them shared in this doc

Could you clarify your use case with more details? Probably we'll be able to find a suitable solution for you

giseliramos commented 10 months ago

Hello @KonstantinTyukalov, the scenario I have:

max-zaytsev commented 3 months ago

Such questions should be posted on the Developer Community, since this repo is mainly about the templates located in this repository.