TriggerTemplates
A TriggerTemplate
is a resource that can template resources.TriggerTemplate
s have parameters that can be substitutedanywhere within the resource template.
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: pipeline-template
spec:
params:
- name: gitrevision
description: The git revision
default: master
- name: gitrepositoryurl
description: The git repository url
- name: message
description: The message to print
default: This is the default message
- name: contenttype
description: The Content-Type of the event
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: simple-pipeline-run-
spec:
pipelineRef:
name: simple-pipeline
params:
- name: message
value: $(params.message)
- name: contenttype
value: $(params.contenttype)
resources:
- name: git-source
resourceSpec:
type: git
params:
- name: revision
value: $(params.gitrevision)
- name: url
value: $(params.gitrepositoryurl)
Similar toPipelines,TriggerTemplate
sdo not do any actual work, but instead act as the blueprint for what resourcesshould be created.
If the namespace is omitted, it will be resolved to the EventListener
’snamespace.
The $(uid)
variable is implicitly available throughout a TriggerTemplate
’sresource templates. A random string value is assigned to $(uid)
like thepostfix generated by the Kubernetes generateName
metadata field. One instancewhere there is useful is when resources in a TriggerTemplate
have internalreferences.
The following are additional labels added to all TriggerTemplate
resourcetemplates:
- To help with housekeeping/garbage collection:
tekton.dev/eventlistener
:<EventListenerName>
- To track resources created by the same event:
tekton.dev/triggers-eventid
:<EventID>
To enable support for arbitrary resource types, the resource templates areinternally resolved as byte blobs. As a result, validation on these resources isonly done at event processing time (rather than during TriggerTemplate
creation). :rotating_light: As of now, only Tekton resources can be definedwithin a TriggerTemplate
:rotating_light:
Parameters
TriggerTemplate
s can declare parameters that are supplied by aTriggerBinding
and/or EventListener
. params
must have a name
, and canhave an optional description
and default
value.
params
can be referenced in the TriggerTemplate
using the following variablesubstitution syntax, where <name>
is the name of the parameter:
$(params.<name>)
params
can be referenced in the resourceTemplates
section of aTriggerTemplate
. The purpose of params
is to make TriggerTemplates
reusable.
Best Practices
As of Tekton Pipelines versionv0.8.0, users canembed resource specs. It is a best practice to embed each resource specs in thePipelineRun or TaskRun that uses the resource spec. Embedding the resource specavoids a race condition between creating and using resources.