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 aTrigger
object.metadata
- Specifies metadata to uniquely identify thisTrigger
object; 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 existingTriggerBinding
or embedded aTriggerBinding
definition using aname
/value
pair. - [
template
] - Specifies the correspondingTriggerTemplate
either as a reference as an embeddedTriggerTemplate
definition. - [
interceptors
] - (Optional) specifies one or moreInterceptors
that will process the payload data before passing it to theTriggerTemplate
. ref
- a reference to aClusterInterceptor
orInterceptor
object with the following fields:name
- the name of the referencedClusterInterceptor
kind
- (Optional) specifies that whether the referenced Kubernetes object is aClusterInterceptor
object orNamespacedInterceptor
. Default value isClusterInterceptor
- [
serviceAccountName
] - (Optional) Specifies theServiceAccount
to supply to theEventListener
to 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
name
parameter to reference an externalTriggerTemplate
object, or -
Use the
spec
parameter to directly embed aTriggerTemplate
definition.
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?