概要
ループの手前で変数を定義し、それを参照します。
例
まずvalues.yamlの変数を定義
repository:
username: craftsman-software
name: focas
branches:
- name: main
project: focas
service: web
environment: prod
- name: prototype
project: focas
service: web
environment: prototype
# ループの前で変数定義
{{ $repositoryFullName := printf "%s/%s" .Values.repository.username .Values.repository.name }}
apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
name: eventlistener-focas
namespace: focas
spec:
serviceAccountName: focas-pipeline-sa
triggers:
{{- range .Values.branches }}
- name: github-push-listener-for-{{ .name }}
interceptors:
- name: "only when specified branch"
ref:
name: cel
params:
- name: filter
# ループないで事前に定義した変数を参照
value: "body.repository.full_name in ['{{ $repositoryFullName }}']"
- name: filter
value: "body.ref in ['refs/heads/{{ .name }}']"
bindings:
- ref: pipelinebinding-focas-for-{{ .name }}
template:
ref: triggertemplate-focas
{{- end }}