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 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
TaskYAML 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: - installThis
Taskstarts a pod and runs a container inside that pod using themaven:3.6.0-jdk-8-slimimage to run the specified commands. It receives an input directory calledworkspace-gitwhich contains the source code of the application.Only the requirement for a git repository is declared on the
Taskand not a specific git repository to be used. This allowsTasksto be reusable for multiplePipelines and purposes. -
Create the
Taskwithin your project:oc create -f maven-build-task.yaml
-
-
Install the
apply-manifestsandupdate-deploymenttasks from the repositories, which contain a list of reusableTasksfor `Pipeline`s:$ 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
-
Verify the
Tasksadded to thePipelineas follows:$ tkn task ls NAME AGE apply-manifests 10 seconds ago update-deployment 4 seconds ago
-
Verify Operator installed additional tasks -
buildahands2i-python-3:$ tkn clustertask ls NAME AGE buildah 9 hours ago buildah-v0-8-0 9 hours ago openshift-client 9 hours ago openshift-client-v0-8-0 9 hours ago s2i 9 hours ago s2i-go 9 hours ago s2i-go-v0-8-0 9 hours ago s2i-java-11 9 hours ago s2i-java-11-v0-8-0 9 hours ago s2i-java-8 9 hours ago s2i-java-8-v0-8-0 9 hours ago s2i-nodejs 9 hours ago s2i-nodejs-v0-8-0 9 hours ago s2i-python-3 9 hours ago s2i-python-3-v0-8-0 9 hours ago s2i-v0-8-0 9 hours ago
Additional resources
-
For more examples of reusable
Taskssee the Tekton Catalog and OpenShift Catalog repositories.