Defining and creating pipeline tasks

Tasks are the building blocks of a Pipeline and consist of sequentially executed steps. steps are a series of commands that achieve a specific goal, for example, build an image.

Every Task runs as a pod and each step runs in its own container within the same pod. Since they run within the same pod they have access to the same volumes to cache files, configmaps, and secrets. They use inputs parameters, for example, a git , and outputs parameters, for example, an image in a registry, to interact with other tasks.

Tasks are reusable and can be used in multiple Pipelines.

Here is an example of a Maven Task with a single step to build a Maven-based Java application.

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: maven-build
spec:
  inputs:
    resources:
    - name: workspace-git
      targetPath: /
      type: git
  steps:
  - name: build
    image: maven:3.6.0-jdk-8-slim
    command:
    - /usr/bin/mvn
    args:
    - install

This Task starts a pod and runs a container inside that pod using the maven:3.6.0-jdk-8-slim image to run the specified commands. It receives an input directory called workspace-git which contains the source code of the application.

Only the requirement for a git repository is declared on the Task and not a specific git repository to be used. This allows Tasks to be reusable for multiple Pipelines and purposes.

Procedure

  1. Install the apply-manifests and update-deployment tasks from the repositories, which contain a list of reusable Tasks for Pipelines:

    $ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/pipeline/update_deployment_task.yaml
    $ oc create -f https://raw.githubusercontent.com/openshift/pipelines-tutorial/master/pipeline/apply_manifest_task.yaml
  2. Verify the Tasks added to the Pipeline as follows:

    $ tkn task ls
    
    NAME              AGE
    apply-manifests     10 seconds ago
    update-deployment   4 seconds ago
  3. Verify Operator installed additional tasks -buildah and s2i-python-3:

    $ tkn clustertask ls
    NAME                       AGE
    buildah                    4 minutes ago
    buildah-v0-10-0            4 minutes ago
    openshift-client           4 minutes ago
    openshift-client-v0-10-0   4 minutes ago
    s2i                        4 minutes ago
    s2i-go                     4 minutes ago
    s2i-go-v0-10-0             4 minutes ago
    s2i-java-11                4 minutes ago
    s2i-java-11-v0-10-0        4 minutes ago
    s2i-java-8                 4 minutes ago
    s2i-java-8-v0-10-0         4 minutes ago
    s2i-nodejs                 4 minutes ago
    s2i-nodejs-v0-10-0         4 minutes ago
    s2i-perl                   4 minutes ago
    s2i-perl-v0-10-0           4 minutes ago
    s2i-php                    4 minutes ago
    s2i-php-v0-10-0            4 minutes ago
    s2i-python-3               4 minutes ago
    s2i-python-3-v0-10-0       4 minutes ago
    s2i-ruby                   4 minutes ago
    s2i-ruby-v0-10-0           4 minutes ago
    s2i-v0-10-0                4 minutes ago

Additional resources