IBM Developer Blog

Follow the latest happenings with IBM Developer and stay in the know.

Learn more about Tekton version 0.10.0's new features, fixes, and more.


Tekton, Tekton, Tekton! Recently, Tekton, a cloud-native continuous integration (CI) and continuous delivery (CD) system designed to help you build, test, and deploy to Kubernetes, has become a hot topic within the developer community.

To kick off the new year, Tekton released version 0.10.0, titled Bombay Robbie. Having grown up in a city named Bombay, I found this nickname to be particularly neat! But besides an awesome moniker, Bombay Robbie comes equipped with a list of new features, fixes, deprecations, backward incompatible changes, and more.

In this blog, I highlight a few of the new features that I find to be interesting.

Simplified script mode

If you’re familiar with Tekton, you may remember using command in your task steps or conditions. The previous Tekton release, Bengal Bender (or version 0.9.0), simplified the pipeline by introducing script. Just when I thought it couldn’t get any simpler, Bombay Robbie simplifies things by adding default shebang #!/bin/sh followed by set -xe when a shebang is missing. This standard bash set command enables two options:

  1. The ability to print a command before its executed.
  2. The ability to exit immediately if a command exits with a non-zero status.

Let’s take a look at the differences between using command and script.

When using command, your code would look something like this:

- name: echo-hello-world
  image: ubuntu
  command:
    - bash
  args:
    - -c
    - |
      echo "Hello World!"

Here’s what it should look like when using a single line script:

- name: echo-hello-world
  image: ubuntu
  script: 'echo "Hello World!"'

Note that you can use a multi-line script, which would look something like this:

- name: echo-hello-world
  image: ubuntu
  script: |
    echo "Hello World!"

Lastly, this is what a script file exmaple looks like:

- name: echo-hello-world
  image: ubuntu
  script: |
    /workspace/script.sh

Bombay Robbie has even implemented the same script mode for pipeline conditions. A script becomes invoked as if it were the contents of a file in the container, which can help simplify a YAML task by moving a list of commands to a file. This script can also be maintained inside a GitHub repo which can be shared across tasks without duplicating the code.

Added workspace support to task and pipeline

Do you miss having access to a common scratchpad from all the tasks under a pipeline? Not anymore! Bombay Robbie features workspace, which provides shared storage, accessible by all the tasks in a pipeline. Workspace can be bound to several types of volumes, including persistentVolumeClaim (PVC), emptyDir, configMap, and secret.

Here is an example of how one task can install NPM packages and send them to the next task to create a zip file, which then can be consumed by the subsequent task:

# Task to install NPM packages
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: pull-dependencies
spec:
  inputs:
    resources:
    - name: source
      type: git
  outputs:
    resources:
    - name: source
      type: git
  steps:
  - name: install-dependencies
    image: nodejs
    script: |
      cd $(inputs.resources.source.path)/
      npm install --production --loglevel=error
      cp -r $(inputs.resources.source.path)/* $(outputs.resources.source.path)
---
# Task to build archive from the source including its dependencies
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: build-archive
spec:
  inputs:
    resources:
    - name: source
      type: git
  outputs:
    resources:
    - name: source
      type: git
  steps:
  - name: install-dependencies
    image: nodejs
    script: |
      cd $(inputs.resources.source.path)/
      zip source.zip -r *
      cp -r $(inputs.resources.source.path)/* $(outputs.resources.source.path)
---
...

Here’s an example of what it looks like to simplify these tasks to use workspace instead of inputs and outputs:

# Task to clone source repo
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: clone-source-to-workspace
spec:
  workspaces:
    - name: scratchpad
  inputs:
    resources:
      - name: source
        type: git
        targetPath: source
  steps:
    - name: clone-source-to-scratchpad
      image: ubuntu
      script: |
        cp -avr $(inputs.resources.source.path)/ $(workspaces.scratchpad.path)/
---
# Task to install NPM packages
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: pull-dependencies
spec:
  workspaces:
    - name: scratchpad
  steps:
  - name: install-dependencies
    image: nodejs
    script: |
      cd $(workspaces.scratchpad.path)/
      npm install --production --loglevel=error
---
# Task to build archive from the source including its dependencies
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: build-archive
spec:
  workspaces:
    - name: scratchpad
  steps:
  - name: install-dependencies
    image: nodejs
    script: |
      cd $(workspaces.scratchpad.path)/
      zip source.zip -r *
---

Workspace allows users to use volumes with tasks. This means two things:

  1. A YAML task can declare the path which gets created at the runtime.
  2. This path can be shared by multiple tasks within a pipeline. For example, a task can clone an application repo into a workspace and have the rest of the tasks in the pipeline operate on that workspace.

Pipeline resource enhancements

Bombay Robbie enables task authors to declare optional input resources. Before, all declared pipeline resources were mandatory and there was no way to mark them as optional. In this release, Bombay Robbie introduces a new key called optional, which is false by default. However, it can be set to true to make a declared pipeline resource unrequired.

Take a look at a task with an optional git pipeline resource:

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
 name: task-check-source
spec:
 inputs:
   resources:
     - name: source
       type: git
       optional: true
 steps:
   - name: check-source
...

Input parameters are considered optional when declared with default values and are considered required without default values. The same approach cannot be followed with input/output resources since pipeline resources are of different types. These different types include Git, an image, a pull request, a cluster, storage, and more, making it impossible to have defaults for these resources. This is when the new optional key comes in handy. This new feature enables use cases such as the deployment to a specified cluster (but defaults to the cluster it is running in) and pull source code from GitHub repositories to build an image if specified.

Embedded taskSpec under pipelineSpec

Version 8.0’s Peterbald Maria added support to embed resourceSpec and pipelineSpec under pipelineRun. Bombay Robbie finishes resources embedding by adding support to embed taskSpec under pipelineRun.

For example:

apiVersion: tekton.dev/v1alpha1
kind: PipelineRun
metadata:
  name: pipelinerun-echo-greetings
spec:
  pipelineSpec:
    tasks:
      - name: echo-good-morning
        taskSpec:

The three benefits of embedding resources, tasks, and pipeline under pipelineRun are:

  1. It makes it easy to create a pipelineRun without creating a pipeline and task first.
  2. It makes it possible to define all necessary resources under pipelineSpec without needing any resources to exist first.
  3. It reduces pipeline/task custom resource definitions (CRDs) lying around the cluster.

Summary

With new features and enhancements, Bombay Robbie makes using Tekton pipelines a little bit easier. If you’re interested in learning more about Tekton and building on your knowledge, see Introduction to Tekton architecture and design. Next, take a hands-on approach by trying a tutorial such as Deploy a Knative application using Tekton Pipelines.

Priti Desai