Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate "for loop" in YAML file

Tags:

yaml

suppose we have the following YAML

a:
  - s1: p
  - s2: p
  - s3: p
  - s4: p

is there a syntax using for loop to generate this YAML file

like:

enum: [s1,s2,s3,s4]
a:
for t in enum:
  -t:p

writing a script is a way to do this. Is this feasible?

like image 887
curtank Avatar asked Mar 15 '19 10:03

curtank


2 Answers

There is no way to shorten a YAML file the way you are planning to do.

A solution would be a script that interprets the file and shortens it the way you like, which would only be usable for readability.

like image 85
Nikolas Avatar answered Sep 29 '22 04:09

Nikolas


I believe you are trying something like yaml template in azure devops : Try something like:

${{each img in parameters.images}}:
      ${{img.key}}:
like image 28
Sid Avatar answered Sep 29 '22 03:09

Sid