Difficulty: Beginner
Estimated Time: 30

Introduction to the Tekton Pipeline

In this tutorial, we will go through:

  • Building a first and second task
  • Building a pipeline
  • Running a pipeline
  • Checking the logs of the run

Additional resources

Now you have the core component of Tekton, Tekton Pipelines, installed on your Kubernetes or OpenShift cluster with the Tekton CLI installed on katacoda. If you would like to continue learning about Tekton, take a look at the following topics:

Tekton Basic Pipeline

Step 1 of 3

Create a basic Task

In this section, we will build the first task.

With Tekton, each operation in your CI/CD workflow becomes a Step, which is executed with a container image you specify. Steps are then organized in Tasks, which run as a Kubernetes pod in your cluster. You can further organize Tasks into Pipelines, which can control the order of execution of several Tasks.

To create a Task, create a Kubernetes object using the Tekton API with the kind Task. The following YAML file specifies a Task with one simple Step, which prints a Hello World! message using the official Ubuntu image:

apiVersion: tekton.dev/v1beta1
kind: Task
  name: hello
    - name: hello
      image: ubuntu
      script: |
        set -e
        echo "Hello World!"

Write the YAML above to a file named task-hello.yaml, and apply it to your Kubernetes cluster:

kubectl apply -f task-hello.yaml

To run this task with Tekton, you need to create a TaskRun, which is another Kubernetes object used to specify run time information for a Task.

To view this TaskRun object you can run the following Tekton CLI (tkn) command:

tkn task start hello --dry-run

After running the command above, the following TaskRun definition should be shown:

apiVersion: tekton.dev/v1beta1
kind: TaskRun
  generateName: hello-run-
    name: hello

To use the TaskRun above to start the hello Task, you can either use tkn or kubectl.

Start with tkn:

tkn task start hello

Start with kubectl:

# use tkn's --dry-run option to save the TaskRun to a file
tkn task start hello --dry-run > taskRun-hello.yaml
# create the TaskRun
kubectl create -f taskRun-hello.yaml

Tekton will now start running your Task. To see the logs of the last TaskRun, run the following tkn command:

tkn taskrun logs --last -f

It may take a few moments before your Task completes. When it executes, it should show the following output:

[hello] Hello World!