1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-07 00:48:01 +01:00
Files
openshift-docs/modules/op-adding-triggers.adoc
2020-11-30 09:55:25 -05:00

171 lines
4.6 KiB
Plaintext

// This module is included in the following assembly:
//
// *openshift_pipelines/creating-applications-with-cicd-pipelines.adoc
[id="adding-triggers_{context}"]
= Adding Triggers to a Pipeline
Triggers enable pipelines to respond to external GitHub events, such as push events and pull requests. After you assemble and start a Pipeline for the application, add the `TriggerBinding`, `TriggerTemplate`, `Trigger`, and `EventListener` resources to capture the GitHub events.
[discrete]
.Procedure
. Copy the content of the following sample `TriggerBinding` YAML file and save it:
+
[source,yaml]
----
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
name: vote-app
spec:
params:
- name: git-repo-url
value: $(body.repository.url)
- name: git-repo-name
value: $(body.repository.name)
- name: git-revision
value: $(body.head_commit.id)
----
. Create the `TriggerBinding` resource:
+
[source,terminal]
----
$ oc create -f <triggerbinding-yaml-file-name.yaml>
----
+
Alternatively, you can create the `TriggerBinding` resource directly from the `pipelines-tutorial` Git repository:
+
[source,terminal,subs="attributes+"]
----
$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/{pipelines-ver}/03_triggers/01_binding.yaml
----
. Copy the content of the following sample `TriggerTemplate` YAML file and save it:
+
[source,yaml,subs="attributes+"]
----
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
name: vote-app
spec:
params:
- name: git-repo-url
description: The git repository url
- name: git-revision
description: The git revision
default: {pipelines-ver}
- name: git-repo-name
description: The name of the deployment to be created / patched
resourcetemplates:
- apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: build-deploy-$(tt.params.git-repo-name)-$(uid)
spec:
serviceAccountName: pipeline
pipelineRef:
name: build-and-deploy
params:
- name: deployment-name
value: $(tt.params.git-repo-name)
- name: git-url
value: $(tt.params.git-repo-url)
- name: git-revision
value: $(tt.params.git-revision)
- name: IMAGE
value: image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/$(tt.params.git-repo-name)
workspaces:
- name: shared-workspace
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 500Mi
----
+
The template specifies a volume claim template to create a persistent volume claim for defining the storage volume for the workspace. Therefore, you do not need to create a persistent volume claim to provide data storage.
. Create the `TriggerTemplate` resource:
+
[source,terminal]
----
$ oc create -f <triggertemplate-yaml-file-name.yaml>
----
+
Alternatively, you can create the `TriggerTemplate` resource directly from the `pipelines-tutorial` Git repository:
+
[source,terminal,subs="attributes+"]
----
$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/{pipelines-ver}/03_triggers/02_template.yaml
----
. Copy the contents of the following sample `Trigger` YAML file and save it:
+
[source,yaml]
----
apiVersion: triggers.tekton.dev/v1alpha1
kind: Trigger
metadata:
name: vote-trigger
spec:
serviceAccountName: pipeline
bindings:
- ref: vote-app
template:
name: vote-app
----
. Create the `Trigger` resource:
+
[source,terminal]
----
$ oc create -f <trigger-yaml-file-name.yaml>
----
+
Alternatively, you can create the `Trigger` resource directly from the `pipelines-tutorial` Git repository:
+
[source,terminal,subs="attributes+"]
----
$ oc create -f https://github.com/openshift/pipelines-tutorial/blob/{pipelines-ver}/03_triggers/03_trigger.yaml
----
. Copy the contents of the following sample `EventListener` YAML file and save it:
+
[source,yaml]
----
apiVersion: triggers.tekton.dev/v1alpha1
kind: EventListener
metadata:
name: vote-app
spec:
serviceAccountName: pipeline
triggers:
- triggerRef: vote-trigger
----
. Create the `EventListener` resource:
+
[source,terminal]
----
$ oc create -f <eventlistener-yaml-file-name.yaml>
----
+
Alternatively, you can create the `EvenListener` resource directly from the `pipelines-tutorial` Git repository:
+
[source,terminal,subs="attributes+"]
----
$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/{pipelines-ver}/03_triggers/04_event_listener.yaml
----
. Expose the `EventListener` service as an {product-title} route to make it publicly accessible:
+
[source,terminal]
----
$ oc expose svc el-vote-app
----