How to iterate overy values in array's #789
-
Hello Community I am using YTT to generate multiple pipeline templates, so i want to iterate over data values in an array to get the values based on it's name to the respective job. i would like to iterate over this job to get an output with 3 build jobs with the name of the job based on each one inside stages array, then iterate over the repo from it's array and just get the value name without the key, and the same thing with the params
and this is my data/values:
lastly, I have data-values-file with the following:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
@EmaLinuxawy if you are able to restructure you data values, then you can make templating a little easier. Consider the following: #! values.yaml
#@data/values
---
builds:
- name: dev
repo: dev-repo
params:
dev-param1: dev-value1
- name: prod
repo: prod-repo
params:
prod-param1: prod-value1 #! config.yaml
#@ load("@ytt:data", "data")
#@ def job(build):
name: #@ build.name
plan:
- in_parallel:
- get: #@ build.repo
trigger: true
- task: build
file: path/to/file.yaml
params: #@ build.params
#@ end
jobs:
#@ for/end build in [s for s in data.values.builds]:
- #@ job(build) Running jobs:
- name: dev
plan:
- in_parallel:
- get: dev-repo
trigger: true
- task: build
file: path/to/file.yaml
params:
dev-param1: dev-value1
- name: prod
plan:
- in_parallel:
- get: prod-repo
trigger: true
- task: build
file: path/to/file.yaml
params:
prod-param1: prod-value1 |
Beta Was this translation helpful? Give feedback.
-
@mamachanko Thanks a lot for your answer, the idea is some pipeline that i need to generate they have more than 14 different jobs, and each job has around 7 lines of params, so I would like to make the data/values file is simple as possible, and the other file that contains only the parameters |
Beta Was this translation helpful? Give feedback.
-
this is another way you can do it |
Beta Was this translation helpful? Give feedback.
-
That was actually what i'm looking for, Thanks a lot @vrabbi |
Beta Was this translation helpful? Give feedback.
this is another way you can do it
https://carvel.dev/ytt/#gist:https://gist.github.com/vrabbi/642414d8ea5a13c7f4cb070bc5d025c1