Task

A Task (or a ClusterTask) is a collection of sequential steps that run as part of a continuous integration flow. A Task runs in the pod on your cluster.

A Task declares:

  • Inputs

  • Outputs

  • Steps

A Task is available in a namespace and a ClusterTask is available across the cluster. The sequential execution of Tasks defines a Pipeline. When you create a Pipeline you define the order of the Tasks that you want to run.

steps tasks pipeline

To define a configuration file for a Task resource, specify the following fields:

Required:

  • apiVersion - Specifies the API version.

  • kind - Specify the Task resource object

  • metadata - Specifies data to uniquely identify the Task resource object, for example a name.

  • spec - Specifies the configuration information for the Task resource object. Task steps must be defined. the following fields:

    • steps - Specifies one or more container images that run in your Task.

Optional:

  • inputs - Specifies parameters and PipelineResources needed by your Task. A Task can declare the inputs it needs, which can be either or both:

  • outputs - Specifies PipelineResources created by your Task

  • volumes - Specifies one or more volumes that you want to make available to your Task steps.

  • stepTemplate - Specifies a Container step definition to use as the basis for all steps in a Task.

The following example shows a configured YAML file where the fields are completed:

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
  name: example-task-name
spec:
  inputs:
    resources:
      - name: workspace
        type: git
    params:
      - name: pathToDockerFile
        type: string
        description: The path to the dockerfile to build
        default: /workspace/workspace/Dockerfile
  outputs:
    resources:
      - name: builtImage
        type: image
  steps:
    - name: openshift-example
      image: openshift
      args: ["openshift-build-example", "SECRETS-example.md"]
    - image: gcr.io/example-builders/build-example
      command: ["echo"]
      args: ["$(inputs.params.pathToDockerFile)"]
    - name: dockerfile-pushexample
      image: gcr.io/example-builders/push-example
      args: ["push", "$(outputs.resources.builtImage.url)"]
      volumeMounts:
        - name: docker-socket-example
          mountPath: /var/run/docker.sock
  volumes:
    - name: example-volume
      emptyDir: {}

Additional resources

  • To learn more about configuring files for a Task resource, read about Required Fields.