{"id":18637153,"url":"https://github.com/openshift/pipelines-tutorial","last_synced_at":"2025-05-14T23:08:00.786Z","repository":{"id":35234438,"uuid":"185267152","full_name":"openshift/pipelines-tutorial","owner":"openshift","description":"A step-by-step tutorial showing OpenShift Pipelines","archived":false,"fork":false,"pushed_at":"2025-02-13T10:15:39.000Z","size":18929,"stargazers_count":311,"open_issues_count":2,"forks_count":657,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-04-13T20:40:30.744Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openshift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-06T20:29:50.000Z","updated_at":"2025-04-13T15:51:49.000Z","dependencies_parsed_at":"2024-12-13T14:04:28.982Z","dependency_job_id":"14fc7cba-69ab-4062-85a5-31a3257d99ec","html_url":"https://github.com/openshift/pipelines-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openshift%2Fpipelines-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openshift%2Fpipelines-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openshift%2Fpipelines-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openshift%2Fpipelines-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openshift","download_url":"https://codeload.github.com/openshift/pipelines-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243362,"owners_count":22038046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T05:33:47.226Z","updated_at":"2025-05-14T23:07:55.771Z","avatar_url":"https://github.com/openshift.png","language":"Shell","readme":"# OpenShift Pipelines Tutorial\n\nWelcome to the OpenShift Pipelines tutorial!\n\nOpenShift Pipelines is a cloud-native, continuous integration and delivery (CI/CD) solution for building pipelines using [Tekton](https://tekton.dev). Tekton is a flexible, Kubernetes-native, open-source CI/CD framework that enables automating deployments across multiple platforms (Kubernetes, serverless, VMs, etc) by abstracting away the underlying details.\n\nOpenShift Pipelines features:\n  * Standard CI/CD pipeline definition based on Tekton\n  * Build images with Kubernetes tools such as S2I, Buildah, Buildpacks, Kaniko, etc\n  * Deploy applications to multiple platforms such as Kubernetes, serverless and VMs\n  * Easy to extend and integrate with existing tools\n  * Scale pipelines on-demand\n  * Portable across any Kubernetes platform\n  * Designed for microservices and decentralized teams\n  * Integrated with the OpenShift Developer Console\n\nThis tutorial walks you through pipeline concepts and how to create and run a simple pipeline for building and deploying a containerized app on OpenShift, and in this tutorial, we will use `Triggers` to handle a real GitHub webhook request to kickoff a PipelineRun.\n\nIn this tutorial you will:\n* [Learn about Tekton concepts](#concepts)\n* [Install OpenShift Pipelines](#install-openshift-pipelines)\n* [Deploy a Sample Application](#deploy-sample-application)\n* [Install Tasks](#install-tasks)\n* [Create a Pipeline](#create-pipeline)\n* [Trigger a Pipeline](#trigger-pipeline)\n\n## Prerequisites\n\nYou need an OpenShift 4 cluster in order to complete this tutorial. If you don't have an existing cluster, go to http://try.openshift.com and register for free in order to get an OpenShift 4 cluster up and running on AWS within minutes.\n\nYou will also use the Tekton CLI (`tkn`) through out this tutorial. Download the Tekton CLI by following [instructions](https://github.com/tektoncd/cli#installing-tkn) available on the CLI GitHub repository.\n\n## Concepts\n\nTekton defines a number of [Kubernetes custom resources](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) as building blocks in order to standardize pipeline concepts and provide a terminology that is consistent across CI/CD solutions. These custom resources are an extension of the Kubernetes API that let users create and interact with these objects using `kubectl` and other Kubernetes tools.\n\nThe custom resources needed to define a pipeline are listed below:\n* `Task`: a reusable, loosely coupled number of steps that perform a specific task (e.g. building a container image)\n* `Pipeline`: the definition of the pipeline and the `Tasks` that it should perform\n* `TaskRun`: the execution and result of running an instance of task\n* `PipelineRun`: the execution and result of running an instance of pipeline, which includes a number of `TaskRuns`\n\n![Tekton Architecture](docs/images/tekton-architecture.svg)\n\nIn short, in order to create a pipeline, one does the following:\n* Create custom or install [existing](https://github.com/tektoncd/catalog) reusable `Tasks`\n* Create a `Pipeline` and `PipelineResources` to define your application's delivery pipeline\n* Create a `PersistentVolumeClaim` to provide the volume/filesystem for pipeline execution or provide a `VolumeClaimTemplate` which creates a `PersistentVolumeClaim`\n* Create a `PipelineRun` to instantiate and invoke the pipeline\n\nFor further details on pipeline concepts, refer to the [Tekton documentation](https://github.com/tektoncd/pipeline/tree/master/docs#learn-more) that provides an excellent guide for understanding various parameters and attributes available for defining pipelines.\n\nThe Tekton API enables functionality to be separated from configuration (e.g.\n[Pipelines](https://github.com/tektoncd/pipeline/blob/master/docs/pipelines.md)\nvs\n[PipelineRuns](https://github.com/tektoncd/pipeline/blob/master/docs/pipelineruns.md))\nsuch that steps can be reusable.\n\nTriggers extend the Tekton\narchitecture with the following CRDs:\n\n- [`TriggerTemplate`](https://github.com/tektoncd/triggers/blob/master/docs/triggertemplates.md) - Templates resources to be\n  created (e.g. Create PipelineResources and PipelineRun that uses them)\n- [`TriggerBinding`](https://github.com/tektoncd/triggers/blob/master/docs/triggerbindings.md) - Validates events and extracts\n  payload fields\n- [`Trigger`](https://github.com/tektoncd/triggers/blob/master/docs/triggers.md) - combines TriggerTemplate, TriggerBindings and interceptors.\n- [`EventListener`](https://github.com/tektoncd/triggers/blob/master/docs/eventlisteners.md) -  provides an\n  [addressable](https://github.com/knative/eventing/blob/master/docs/spec/interfaces.md)\n  endpoint (the event sink). `Trigger` is referenced inside the EventListener Spec. It uses the extracted event parameters from each\n  `TriggerBinding` (and any supplied static parameters) to create the resources\n  specified in the corresponding `TriggerTemplate`. It also optionally allows an\n  external service to pre-process the event payload via the `interceptor` field.\n- [`ClusterTriggerBinding`](https://github.com/tektoncd/triggers/blob/master/docs/clustertriggerbindings.md) - A cluster-scoped\n  TriggerBinding\n\nUsing `tektoncd/triggers` in conjunction with `tektoncd/pipeline` enables you to\neasily create full-fledged CI/CD systems where the execution is defined\n**entirely** through Kubernetes resources.\n\nYou can learn more about `triggers` by checking out the [docs](https://github.com/tektoncd/triggers/blob/master/docs/README.md)\n\nIn the following sections, you will go through each of the above steps to define and invoke a pipeline.\n\n## Install OpenShift Pipelines\n\nOpenShift Pipelines is provided as an add-on on top of OpenShift that can be installed via an operator available in the OpenShift OperatorHub. Follow [these instructions](install-operator.md) in order to install OpenShift Pipelines on OpenShift via the OperatorHub.\n\n![OpenShift OperatorHub](docs/images/operatorhub.png)\n\n## Deploy Sample Application\n\nCreate a project for the sample application that you will be using in this tutorial:\n\n```bash\n$ oc new-project pipelines-tutorial\n```\n\nOpenShift Pipelines automatically adds and configures a `ServiceAccount` named `pipeline` that has sufficient permissions to build and push an image. This\nservice account will be used later in the tutorial.\n\nRun the following command to see the `pipeline` service account:\n\n```bash\n$ oc get serviceaccount pipeline\n```\n\nYou will use the simple application during this tutorial, which has a [frontend](https://github.com/openshift/pipelines-vote-ui) and [backend](https://github.com/openshift/pipelines-vote-api)\n\nYou can also deploy the same applications by applying the artifacts available in k8s directory of the respective repo\n\nIf you deploy the application directly, you should be able to see the deployment in the OpenShift Web Console by switching over to the **Developer** perspective of the OpenShift Web Console. Change from **Administrator** to **Developer** from the drop down as shown below:\n\n![Developer Perspective](docs/images/developer.png)\n\nMake sure you are on the `pipelines-tutorial` project by selecting it from the **Project** dropdown menu. Either search for `pipelines-tutorial` in the search bar or scroll down until you find `pipelines-tutorial` and click on the name of your project.\n\n![Projects](docs/images/projects.png)\n\n\u003c!--\nOn the **Topology** view of the **Developer** perspective, you will be able to see the resources you just created.\n\n![Projects](docs/images/application-deployed.png)\n--\u003e\n\n## Install Tasks\n\nTasks consist of a number of steps that are executed sequentially. Tasks are executed/run by creating TaskRuns. A TaskRun will schedule a Pod. Each step is executed in a separate container within the same pod. They can also have inputs and outputs in order to interact with other tasks in the pipeline.\n\nHere is an example of a Maven task for building a Maven-based Java application:\n\n```yaml\napiVersion: tekton.dev/v1\nkind: Task\nmetadata:\n  name: maven-build\nspec:\n  workspaces:\n   - name: filedrop\n  steps:\n  - name: build\n    image: maven:3.6.0-jdk-8-slim\n    command:\n    - /usr/bin/mvn\n    args:\n    - install\n```\n\nWhen a task starts running, it starts a pod and runs each step sequentially in a separate container on the same pod. This task happens to have a single step, but tasks can have multiple steps, and, since they run within the same pod, they have access to the same volumes in order to cache files, access configmaps, secrets, etc. You can specify volume using workspace. It is recommended that Tasks uses at most one writeable Workspace. Workspace can be secret, pvc, config or emptyDir.\n\nNote that only the requirement for a git repository is declared on the task and not a specific git repository to be used. That allows tasks to be reusable for multiple pipelines and purposes. You can find more examples of reusable tasks in the [Tekton Catalog](https://github.com/tektoncd/catalog) and [OpenShift Catalog](https://github.com/openshift/pipelines-catalog) repositories.\n\nInstall the `apply-manifests` and `update-deployment` tasks from the repository using `oc` or `kubectl`, which you will need for creating a pipeline in the next section:\n\n```bash\n$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/01_pipeline/01_apply_manifest_task.yaml\n\n$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/01_pipeline/02_update_deployment_task.yaml\n```\n\nYou can take a look at the tasks you created using the [Tekton CLI](https://github.com/tektoncd/cli/releases):\n\n```\n$ tkn task ls\n\nNAME                AGE\napply-manifests     10 seconds ago\nupdate-deployment   4 seconds ago\n```\n\nWe will be using `buildah` task, which gets installed along with Operator. Operator installs few tasks in namespace `openshift-pipelines` which you can see.\n\n```bash\n$ tkn tasks ls -n openshift-pipelines\nNAME                      DESCRIPTION              AGE\nbuildah                   Buildah task builds...   1 day ago\ngit-cli                   This task can be us...   1 day ago\ngit-clone                 This object represe...   1 day ago\nmaven                     This Task can be us...   1 day ago\n...\n```\n\n## Create Pipeline\n\nA pipeline defines a number of tasks that should be executed and how they interact with each other via their inputs and outputs.\n\nIn this tutorial, you will create a pipeline that takes the source code of the application from GitHub and then builds and deploys it on OpenShift.\n\n![Pipeline Diagram](docs/images/pipeline-diagram.png)\n\nHere is the YAML file that represents the above pipeline:\n\n```yaml\napiVersion: tekton.dev/v1\nkind: Pipeline\nmetadata:\n  name: build-and-deploy\nspec:\n  workspaces:\n  - name: shared-workspace\n  params:\n  - name: deployment-name\n    type: string\n    description: name of the deployment to be patched\n  - name: git-url\n    type: string\n    description: url of the git repo for the code of deployment\n  - name: git-revision\n    type: string\n    description: revision to be used from repo of the code for deployment\n    default: master\n  - name: IMAGE\n    type: string\n    description: image to be build from the code\n  tasks:\n  - name: fetch-repository\n    taskRef:\n      resolver: cluster\n      params:\n      - name: kind\n        value: task\n      - name: name\n        value: git-clone\n      - name: namespace\n        value: openshift-pipelines\n    workspaces:\n    - name: output\n      workspace: shared-workspace\n    params:\n    - name: URL\n      value: $(params.git-url)\n    - name: SUBDIRECTORY\n      value: \"\"\n    - name: DELETE_EXISTING\n      value: \"true\"\n    - name: REVISION\n      value: $(params.git-revision)\n  - name: build-image\n    taskRef:\n      resolver: cluster\n      params:\n      - name: kind\n        value: task\n      - name: name\n        value: buildah\n      - name: namespace\n        value: openshift-pipelines\n    params:\n    - name: IMAGE\n      value: $(params.IMAGE)\n    workspaces:\n    - name: source\n      workspace: shared-workspace\n    runAfter:\n    - fetch-repository\n  - name: apply-manifests\n    taskRef:\n      name: apply-manifests\n    workspaces:\n    - name: source\n      workspace: shared-workspace\n    runAfter:\n    - build-image\n  - name: update-deployment\n    taskRef:\n      name: update-deployment\n    params:\n    - name: deployment\n      value: $(params.deployment-name)\n    - name: IMAGE\n      value: $(params.IMAGE)\n    runAfter:\n    - apply-manifests\n```\nOnce you deploy the pipelines, you should be able to visualize pipeline flow in the OpenShift Web Console by switching over to the **Developer** perspective of the OpenShift Web Console. Select pipeline tab, select project as `pipelines-tutorial` and click on pipeline `build-and-deploy`\n\n![Pipeline-view](docs/images/pipeline-view.png)\n\nThis pipeline helps you to build and deploy backend/frontend, by configuring right resources to pipeline.\n\nPipeline Steps:\n\n  1. Clones the source code of the application from a git repository by referring (`git-url` and `git-revision` param)\n  2. Builds the container image of application using the `buildah` task\n  that uses [Buildah](https://buildah.io/) to build the image\n  3. The application image is pushed to an image registry by refering (`image` param)\n  4. The new application image is deployed on OpenShift using the `apply-manifests` and `update-deployment` tasks.\n\nYou might have noticed that there are no references to the git\nrepository or the image registry it will be pushed to in pipeline. That's because pipeline in Tekton\nare designed to be generic and re-usable across environments and stages through\nthe application's lifecycle. Pipelines abstract away the specifics of the git\nsource repository and image to be produced as `PipelineResources` or `Params`. When triggering a\npipeline, you can provide different git repositories and image registries to be\nused during pipeline execution. Be patient! You will do that in a little bit in\nthe next section.\n\nThe execution order of tasks is determined by dependencies that are defined between the tasks via inputs and outputs as well as explicit orders that are defined via `runAfter`.\n\n`workspaces` field allows you to specify one or more volumes that each Task in the Pipeline requires during execution. You specify one or more Workspaces in the `workspaces` field.\n\nCreate the pipeline by running the following:\n\n```bash\n$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/01_pipeline/04_pipeline.yaml\n```\n\nAlternatively, in the OpenShift Web Console, you can click on the **+** at the top right of the screen while you are in the **pipelines-tutorial** project:\n\n![OpenShift Console - Import Yaml](docs/images/console-import-yaml.png)\n\nUpon creating the pipeline via the web console, you will be taken to a **Pipeline Details** page that gives an overview of the pipeline you created.\n\u003c!-- \u003e\n\n![OpenShift Console - Pipeline Details](docs/images/pipeline-details.png)\n\n--\u003e\n\nCheck the list of pipelines you have created using the CLI:\n\n```\n$ tkn pipeline ls\n\nNAME               AGE            LAST RUN   STARTED   DURATION   STATUS\nbuild-and-deploy   1 minute ago   ---        ---       ---        ---\n```\n\n## Trigger Pipeline\n\nNow that the pipeline is created, you can trigger it to execute the tasks\nspecified in the pipeline.\n\n\u003e **Note** :-\n\u003e\n\u003eIf you are not into the `pipelines-tutorial` namespace, and using another namespace for the tutorial steps, please make sure you update the\nfrontend and backend image resource to the correct url with your namespace name like so :\n\u003e\n\u003e`image-registry.openshift-image-registry.svc:5000/\u003cnamespace-name\u003e/pipelines-vote-api:latest`\n\n\n\nA `PipelineRun` is how you can start a pipeline and tie it to the persistentVolumeClaim and params that should be used for this specific invocation.\n \nLet's start a pipeline to build and deploy the backend application using `tkn`:\n\n```bash\n$ tkn pipeline start build-and-deploy \\\n    --prefix-name build-deploy-api-pipelinerun \\\n    -w name=shared-workspace,volumeClaimTemplateFile=https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/01_pipeline/03_persistent_volume_claim.yaml \\\n    -p deployment-name=pipelines-vote-api \\\n    -p git-url=https://github.com/openshift/pipelines-vote-api.git \\\n    -p IMAGE=image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/pipelines-vote-api \\\n    --use-param-defaults\n\n\nPipelinerun started: vote-api-t9tpq\n\nIn order to track the pipelinerun progress run:\ntkn pipelinerun logs vote-api-t9tpq -f -n pipelines-tutorial\n```\n\nSimilarly, start a pipeline to build and deploy the frontend application:\n\n```bash\n$ tkn pipeline start build-and-deploy \\\n    --prefix-name build-deploy-ui-pipelinerun \\\n    -w name=shared-workspace,volumeClaimTemplateFile=https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/01_pipeline/03_persistent_volume_claim.yaml \\\n    -p deployment-name=pipelines-vote-ui \\\n    -p git-url=https://github.com/openshift/pipelines-vote-ui.git \\\n    -p IMAGE=image-registry.openshift-image-registry.svc:5000/pipelines-tutorial/pipelines-vote-ui \\\n    --use-param-defaults\n\nPipelineRun started: vote-ui-9tb2q\n\nIn order to track the PipelineRun progress run:\ntkn pipelinerun logs vote-ui-9tb2q -f -n pipelines-tutorial\n```\nAs soon as you start the `build-and-deploy` pipeline, a pipelinerun will be instantiated and pods will be created to execute the tasks that are defined in the pipeline.\n\n```bash\n$ tkn pipeline list\nNAME               AGE              LAST RUN        STARTED          DURATION   STATUS\nbuild-and-deploy   10 minutes ago   vote-ui-9tb2q   47 seconds ago   ---        Running\n```\n\nAbove we have started `build-and-deploy` pipeline, with relevant pipeline resources to deploy the backend/frontend applications using single pipeline\n\n```bash\n$ tkn pipelinerun ls\nNAME             STARTED         DURATION   STATUS\nvote-ui-9tb2q    1 minute ago    ---        Running\nvote-api-t9tpq   1 minute ago    ---        Running\n```\n\n\nCheck out the logs of the pipelinerun as it runs using the `tkn pipeline logs` command which interactively allows you to pick the pipelinerun of your interest and inspect the logs:\n\n```\n$ tkn pipeline logs -f\n? Select pipelinerun:  [Use arrows to move, type to filter]\n\u003e vote-ui-9tb2q started 3 minutes ago\n  vote-api-t9tpq started 7 minutes ago\n```\n\nAfter a few minutes, the pipeline should finish successfully.\n\n```bash\n$ tkn pipelinerun list\nNAME             STARTED         DURATION   STATUS\nvote-ui-9tb2q    1 minute ago    1m23s      Succeeded\nvote-api-t9tpq   5 minutes ago   1m31s      Succeeded\n```\n\nLooking back at the project, you should see that the images are successfully built and deployed.\n\n![Application Deployed](docs/images/application-deployed.png)\n\nYou can get the route of the application by executing the following command and access the application\n\n```bash\n$ oc get route pipelines-vote-ui --template='http://{{.spec.host}}'\n```\n\n\nIf you want to re-run the pipeline again, you can use the following short-hand command to rerun the last pipelinerun again that uses the same workspaces, params and service account used in the previous pipeline run:\n\n```\n$ tkn pipeline start build-and-deploy --last\n```\n\nWhenever there is any change to your repository we need to start the pipeline explicitly to see new changes take effect.\n\n# Triggers\nTriggers in conjunction with pipelines enable us to hook our Pipelines to respond to external GitHub events (push events, pull requests etc).\n\n## Prerequisites\n\nYou need an OpenShift 4 cluster running on AWS, Azure or onprem in order to complete this tutorial. If you don't have an existing cluster, go to http://try.openshift.com and register for free in order to get an OpenShift 4 cluster up and running on AWS within minutes.\n\n\u003e***NOTE:*** Running cluster localy [crc](https://github.com/code-ready/crc/releases) won't work, as we need `webhook-url` to be accessable to `github-repos`\n\n### Adding Triggers to our Application:\n\nNow let’s add a TriggerTemplate, TriggerBinding, and an EventListener to our project.\n\n####  Trigger Template\n\nA `TriggerTemplate` is a resource that has parameters that can be substituted anywhere within the resources of a template.\n\nThe definition of our TriggerTemplate is given in `03_triggers/02-template.yaml`.\n\n```yaml\napiVersion: triggers.tekton.dev/v1beta1\nkind: TriggerTemplate\nmetadata:\n  name: vote-app\nspec:\n  params:\n  - name: git-repo-url\n    description: The git repository url\n  - name: git-revision\n    description: The git revision\n    default: master\n  - name: git-repo-name\n    description: The name of the deployment to be created / patched\n\n  resourcetemplates:\n  - apiVersion: tekton.dev/v1\n    kind: PipelineRun\n    metadata:\n      generateName: build-deploy-$(tt.params.git-repo-name)-\n    spec:\n      taskRunTemplate:\n        serviceAccountName: pipeline\n      pipelineRef:\n        name: build-and-deploy\n      params:\n      - name: deployment-name\n        value: $(tt.params.git-repo-name)\n      - name: git-url\n        value: $(tt.params.git-repo-url)\n      - name: git-revision\n        value: $(tt.params.git-revision)\n      - name: IMAGE\n        value: image-registry.openshift-image-registry.svc:5000/$(context.pipelineRun.namespace)/$(tt.params.git-repo-name)\n      workspaces:\n      - name: shared-workspace\n        volumeClaimTemplate:\n          spec:\n            accessModes:\n              - ReadWriteOnce\n            resources:\n              requests:\n                storage: 500Mi\n```\n\nRun the following command to apply Triggertemplate.\n\n```bash\n$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/03_triggers/02_template.yaml\n```\n\n\n####  Trigger Binding\nTriggerBindings is a map enable you to capture fields from an event and store them as parameters, and replace them in triggerTemplate whenever an event occurs.\n\nThe definition of our TriggerBinding is given in `03_triggers/01_binding.yaml`.\n\n```yaml\napiVersion: triggers.tekton.dev/v1beta1\nkind: TriggerBinding\nmetadata:\n  name: vote-app\nspec:\n  params:\n  - name: git-repo-url\n    value: $(body.repository.url)\n  - name: git-repo-name\n    value: $(body.repository.name)\n  - name: git-revision\n    value: $(body.head_commit.id)\n```\nThe exact paths (keys) of the parameters we need can be found by examining the event payload (eg: GitHub events).\n\n\nRun the following command to apply TriggerBinding.\n\n```bash\n$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/03_triggers/01_binding.yaml\n```\n\n####  Trigger\n`Trigger` combines TriggerTemplate, TriggerBindings and interceptors. They are used as ref inside the EventListener.\n\nThe definition of our Trigger is given in `03_triggers/03_trigger.yaml`.\n\n```yaml\napiVersion: triggers.tekton.dev/v1beta1\nkind: Trigger\nmetadata:\n  name: vote-trigger\nspec:\n  serviceAccountName: pipeline\n  interceptors:\n    - ref:\n        name: \"github\"\n      params:\n        - name: \"secretRef\"\n          value:\n            secretName: github-secret\n            secretKey: secretToken\n        - name: \"eventTypes\"\n          value: [\"push\"]\n  bindings:\n    - ref: vote-app\n  template:\n    ref: vote-app\n```\nThe secret is to verify events are coming from the correct source code management.\n\n```yaml\n---\napiVersion: v1\nkind: Secret\nmetadata:\n  name: github-secret\ntype: Opaque\nstringData:\n  secretToken: \"1234567\"\n```\nRun the following command to apply Trigger.\n\n```bash\n$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/03_triggers/03_trigger.yaml\n```\n\n\n#### Event Listener\n\nThis component sets up a Service and listens for events. It also connects a TriggerTemplate to a TriggerBinding, into an\n[addressable](https://github.com/knative/eventing/blob/master/docs/spec/interfaces.md)\nendpoint (the event sink)\n\nThe definition for our EventListener can be found in\n`03_triggers/04_event_listener.yaml`.\n\n```yaml\napiVersion: triggers.tekton.dev/v1beta1\nkind: EventListener\nmetadata:\n  name: vote-app\nspec:\n  serviceAccountName: pipeline\n  triggers:\n    - triggerRef: vote-trigger\n```\n* Run the following command to create EventListener.\n\n```bash\n$ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/03_triggers/04_event_listener.yaml\n```\n\n\u003e***Note***: EventListener will setup a Service. We need to expose that Service as an OpenShift Route to make it publicly accessible.\n\n* Run the below command to expose the EventListener service as a route\n\n```bash\n$ oc expose svc el-vote-app\n```\n\n## Configuring GitHub WebHooks\n\nNow we need to configure webhook-url on [backend](https://github.com/openshift/pipelines-vote-api) and [frontend](https://github.com/openshift/pipelines-vote-ui) source code repositories with the Route we exposed previously.\n\n* Run the below command to get webhook-url\n\n```bash\n$ echo \"URL: $(oc  get route el-vote-app --template='http://{{.spec.host}}')\"\n```\n\n\u003e***Note:***\n\u003e\n\u003eFork the [backend](https://github.com/openshift/pipelines-vote-api) and [frontend](https://github.com/openshift/pipelines-vote-ui) source code repositories so that you have sufficient privileges to configure GitHub webhooks.\n\n### Configure webhook manually\n\nOpen the forked GitHub repo (Go to Settings \u003e Webhook).\nClick on `Add Webhook` \u003e Add\n```bash\n$ echo \"$(oc  get route el-vote-app --template='http://{{.spec.host}}')\"\n```\nto payload URL \u003e Select Content type as `application/json` \u003e Add secret eg: `1234567` \u003e Click on `Add Webhook`\n\n![Add webhook](docs/images/add-webhook.png)\n\n- Follow the above procedure to configure the webhook on [frontend](https://github.com/openshift/pipelines-vote-ui) repo\n\nNow we should see a webhook configured on your forked source code repositories (on our\nGitHub Repo, go to Settings\u003eWebhooks).\n\n![Webhook-final](docs/images/webhooks.png)\n\n***Great!, We have configured webhooks***\n\n#### Trigger pipeline Run\n\nWhen we perform any push event on the [backend](https://github.com/openshift/pipelines-vote-api) the following should happen.\n\n1.  The configured webhook in vote-api GitHub repository should push the event payload to our route (exposed EventListener Service).\n\n2. The Event-Listener will pass the event to the TriggerBinding and TriggerTemplate pair.\n\n3. TriggerBinding will extract parameters needed for rendering the TriggerTemplate.\nSuccessful rendering of TriggerTemplate should create 2 PipelineResources (source-repo-vote-api and image-source-vote-api) and a PipelineRun (build-deploy-vote-api)\n\nWe can test this by pushing a commit to vote-api repository from GitHub web ui or from the terminal.\n\nLet’s push an empty commit to vote-api repository.\n```bash\n$ git commit -m \"empty-commit\" --allow-empty \u0026\u0026 git push origin master\n...\nWriting objects: 100% (1/1), 190 bytes | 190.00 KiB/s, done.\nTotal 1 (delta 0), reused 0 (delta 0)\nTo github.com:\u003cgithub-username\u003e/pipelines-vote-api.git\n   72c14bb..97d3115  master -\u003e master\n```\n\nWatch the OpenShift WebConsole Developer perspective and a PipelineRun will be automatically created.\n\n![pipeline-run-api](docs/images/pipeline-run-api.png\n)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenshift%2Fpipelines-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenshift%2Fpipelines-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenshift%2Fpipelines-tutorial/lists"}