TriggerBindings

As per the name, TriggerBindings bind against events/triggers.TriggerBindings enable you to capture fields from an event and store them asparameters. The separation of TriggerBindings from TriggerTemplates wasdeliberate to encourage reuse between them.

  1. apiVersion: triggers.tekton.dev/v1alpha1
  2. kind: TriggerBinding
  3. metadata:
  4. name: pipeline-binding
  5. spec:
  6. params:
  7. - name: gitrevision
  8. value: $(body.head_commit.id)
  9. - name: gitrepositoryurl
  10. value: $(body.repository.url)
  11. - name: contenttype
  12. value: $(header.Content-Type)

TriggerBindings are connected to TriggerTemplates within anEventListener, which is where the pod is actuallyinstantiated that “listens” for the respective events.

Parameters

TriggerBindings can provide params which are passed to a TriggerTemplate.Each parameter has a name and a value.

Event Variable Interpolation

TriggerBindings can access values from the HTTP JSON body and the headers usingJSONPath expressions wrapped in $(). The key in the header iscase-insensitive.

These are all valid expressions:

  1. $(body.key1)
  2. $(.body.key)

These are invalid expressions:

  1. .body.key1 # INVALID - Not wrapped in $()
  2. $({body) # INVALID - Ending curly brace absent

If the $() is embedded inside another $() we will use the contents of theinnermost $() as the JSONPath expression

  1. $($(body.b)) -> $(body.b)
  2. $($($(body.b))) -> $(body.b)

Examples

  1. `$(body)` is replaced by the entire body.
  2. $(body) -> "{"key1": "value1", "key2": {"key3": "value3"}, "key4": ["value4", "value5", "value6"]}"
  3. $(body.key1) -> "value1"
  4. $(body.key2) -> "{"key3": "value3"}"
  5. $(body.key2.key3) -> "value3"
  6. $(body.key4[0]) -> "value4"
  7. $(body.key4[0:2]) -> "{"value4", "value5"}"
  8. # $(header) is replaced by all of the headers from the event.
  9. $(header) -> "{"One":["one"], "Two":["one","two","three"]}"
  10. $(header.One) -> "one"
  11. $(header.one) -> "one"
  12. $(header.Two) -> "one two three"
  13. $(header.Two[1]) -> "two"

Multiple Bindings

In an EventListener, you may specify multiple bindings aspart of your trigger. This allows you to create reusable bindings that can bemixed and matched with various triggers. For example, a trigger with one bindingthat extracts event information, and another binding that provides deployenvironment information:

  1. apiVersion: triggers.tekton.dev/v1alpha1
  2. kind: TriggerBinding
  3. metadata:
  4. name: event-binding
  5. spec:
  6. params:
  7. - name: gitrevision
  8. value: $(body.head_commit.id)
  9. - name: gitrepositoryurl
  10. value: $(body.repository.url)
  11. ---
  12. apiVersion: triggers.tekton.dev/v1alpha1
  13. kind: TriggerBinding
  14. metadata:
  15. name: prod-env
  16. spec:
  17. params:
  18. - name: environment
  19. value: prod
  20. ---
  21. apiVersion: triggers.tekton.dev/v1alpha1
  22. kind: TriggerBinding
  23. metadata:
  24. name: staging-env
  25. spec:
  26. params:
  27. - name: environment
  28. value: staging
  29. ---
  30. apiVersion: triggers.tekton.dev/v1alpha1
  31. kind: EventListener
  32. metadata:
  33. name: listener
  34. spec:
  35. triggers:
  36. - name: prod-trigger
  37. bindings:
  38. - name: event-binding
  39. - name: prod-env
  40. template:
  41. name: pipeline-template
  42. - name: staging-trigger
  43. bindings:
  44. - name: event-binding
  45. - name: staging-env
  46. template:
  47. name: pipeline-template