Triggers
A Trigger specifies what happens when the EventListener detects an event. A Trigger specifies a TriggerTemplate,
a TriggerBinding, and optionally an Interceptor.
Structure of a Trigger
When creating a Trigger definition you must specify the required fields and can also specify any of the optional fields listed below:
- Required:
apiVersion- Specifies the API version; for exampletriggers.tekton.dev/v1alpha1.kind- Specifies that this resource object is aTriggerobject.metadata- Specifies metadata to uniquely identify thisTriggerobject; for example aname.spec- Specifies the configuration information for this Trigger object, including:- [
bindings] - (Optional) Specifies a list of field bindings; each binding can either reference an existingTriggerBindingor embedded aTriggerBindingdefinition using aname/valuepair. - [
template] - Specifies the correspondingTriggerTemplateeither as a reference as an embeddedTriggerTemplatedefinition. - [
interceptors] - (Optional) specifies one or moreInterceptorsthat will process the payload data before passing it to theTriggerTemplate. ref- a reference to aClusterInterceptororInterceptorobject with the following fields:name- the name of the referencedClusterInterceptorkind- (Optional) specifies that whether the referenced Kubernetes object is aClusterInterceptorobject orNamespacedInterceptor. Default value isClusterInterceptor
- [
serviceAccountName] - (Optional) Specifies theServiceAccountto supply to theEventListenerto instantiate/execute the target resources.
- [
Below is an example Trigger definition:
apiVersion: triggers.tekton.dev/v1beta1
kind: Trigger
metadata:
name: trigger
spec:
interceptors:
- ref:
name: "cel"
params:
- name: "filter"
value: "header.match('X-GitHub-Event', 'pull_request')"
- name: "overlays"
value:
- key: extensions.truncated_sha
expression: "body.pull_request.head.sha.truncate(7)"
bindings:
- ref: pipeline-binding
template:
ref: pipeline-template
Specifying the corresponding TriggerTemplate
In the template field, you can do one of the following:
-
Use the
nameparameter to reference an externalTriggerTemplateobject, or -
Use the
specparameter to directly embed aTriggerTemplatedefinition.
For example:
# Example: embedded TriggerTemplate definition
triggers:
- name: "my-trigger"
template:
spec:
params:
- name: "my-param-name"
resourcetemplates:
- apiVersion: "tekton.dev/v1beta1"
kind: TaskRun
metadata:
generateName: "pr-run-"
spec:
taskSpec:
steps:
- image: ubuntu
script: echo "hello there"
Feedback
Was this page helpful?