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 instance, 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 Pipeline
s. For this tutorial, you create a Maven Task
with a single step to build a Maven based application, and then add two reusable Tasks
from the catalog repository.
Procedure
-
To create the Maven
Task
:-
Copy the contents of the following sample
Task
YAML file and save it: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 themaven:3.6.0-jdk-8-slim
image to run the specified commands. It receives an input directory calledworkspace-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 allowsTasks
to be reusable for multiplePipeline
s and purposes. -
Create the
Task
within your project:oc create -f maven-build-task.yaml
-
-
Install the
s2i-java
andopenshift-client
reusableTasks
from the catalog repository, which contains a list of reusableTasks
forPipeline
s:$ oc create -f https://raw.githubusercontent.com/tektoncd/catalog/master/openshift-client/openshift-client-task.yaml $ oc create -f https://raw.githubusercontent.com/openshift/pipelines-catalog/master/s2i-java8/s2i-java-8-task.yaml
-
Verify the
Tasks
added to thePipeline
as follows:$ tkn task ls NAME AGE maven-build 23 secs ago openshift-client 10 secs ago s2i-java 11 secs ago
Additional resources
-
For more examples of reusable
Tasks
see the Tekton Catalog and OpenShift Catalog repositories.