Using OpenShift Pipelines

Automated builds and deployments – known as CI/CD – of container-based applications can reduce mistakes, improve productivity, and promote more thorough testing. This learning path introduces OpenShift Pipelines for automated builds and deployment.

OpenShift Pipelines is added to a Red Hat OpenShift cluster by the OpenShift Pipelines operator. This operator is already installed in the Developer Sandbox. So all we need to do is create objects and run our pipelines.

Learn more about the Developer Sandbox

Ready to get started? In this lesson, you will clone the GitHub repository and prepare a pipeline. 

In order to get full benefit from taking this lesson, you need to:

  • A web browser.

In this lesson, you will:

  • Clone a repository.
  • Create your pipeline.

Clone the GitHub repository

Where you put this on your PC will be your working directory. You will change some of the code based on your sandbox. Run the following command to clone the GitHub repo to your PC:

git clone https://github.com/redhat-developer-demos/openshift-pipelines-workshop

Prerequisites

We will create the pipeline object from the command line. The only tool needed is the oc command-line interface. The contents of the qotd-pipeline.yaml file are as follows:

apiVersion: tekton.dev/v1beta1 

kind: Pipeline 

metadata:

  name: qotd-build-and-deploy 

spec: 

  workspaces: 

  - name: shared-workspace

  params: 

  - name: git-url

    type: string

    description: url of the git repo for the code of deployment

    default: https://github.com/redhat-developer-demos/qotd.git

  - name: IMAGE

    type: string

    description: image to be built from the code

    default: image-registry.openshift-image-registry.svc:5000/<<project_name>>/qotd:latest

  tasks: 

  - name: fetch-repository

    taskRef:

      name: git-clone

      kind: ClusterTask

    workspaces:

    - name: output

      workspace: shared-workspace

    params:

    - name: url

      value: $(params.git-url)

    - name: subdirectory

      value: ""

    - name: deleteExisting

      value: "true"

  - name: build-image 

    taskRef:

      name: buildah

      kind: ClusterTask

    params:

    - name: TLSVERIFY

      value: "false"

    - name: IMAGE

      value: $(params.IMAGE)

    workspaces:

    - name: source

      workspace: shared-workspace

    runAfter:

    - fetch-repository

  - name: apply-manifests 

    taskRef:

      name: apply-manifests

    workspaces:

    - name: source

      workspace: shared-workspace

    runAfter: 

    - build-image

Notice the IMAGE parameter and, specifically, its default value. That value will not work. It must be changed.

There are two ways to change the value:

  • Change the value in this file using a text editor, or
  • Override the value when you use the tkn command-line tool to run this pipeline.

Given this knowledge, we realize we can also change the value of the git-url parameter at the command line. This means this pipeline can be reused. Take a GitHub repo that we specify at the command line and build a Linux image, then deposit that image into an image registry, specified at the command line.

Create the pipeline

Run the following command to create the qotd-build-and-deploy pipeline object:

oc apply -f qotd-pipeline.yaml

Congratulations. You've cloned the repository and created your pipeline. It's time move on to the next lesson and learn about containerization and Tilt.

Previous resource
Overview: Using OpenShift Pipelines
Next resource
Create necessary tasks within a new workspace