TriggerTemplates

A TriggerTemplate is a resource that can template resources.TriggerTemplates have parameters that can be substitutedanywhere within the resource template.

  1. apiVersion: triggers.tekton.dev/v1alpha1
  2. kind: TriggerTemplate
  3. metadata:
  4. name: pipeline-template
  5. spec:
  6. params:
  7. - name: gitrevision
  8. description: The git revision
  9. default: master
  10. - name: gitrepositoryurl
  11. description: The git repository url
  12. - name: message
  13. description: The message to print
  14. default: This is the default message
  15. - name: contenttype
  16. description: The Content-Type of the event
  17. resourcetemplates:
  18. - apiVersion: tekton.dev/v1beta1
  19. kind: PipelineRun
  20. metadata:
  21. generateName: simple-pipeline-run-
  22. spec:
  23. pipelineRef:
  24. name: simple-pipeline
  25. params:
  26. - name: message
  27. value: $(params.message)
  28. - name: contenttype
  29. value: $(params.contenttype)
  30. resources:
  31. - name: git-source
  32. resourceSpec:
  33. type: git
  34. params:
  35. - name: revision
  36. value: $(params.gitrevision)
  37. - name: url
  38. value: $(params.gitrepositoryurl)

Similar toPipelines,TriggerTemplatesdo 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 TriggerTemplatecreation). :rotating_light: As of now, only Tekton resources can be definedwithin a TriggerTemplate :rotating_light:

Parameters

TriggerTemplates 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:

  1. $(params.<name>)

params can be referenced in the resourceTemplates section of aTriggerTemplate. The purpose of params is to make TriggerTemplatesreusable.

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.