Skip to main content

My First Pipeline

Knowing that pipelines are grouped tasks let's get straight to the point. If tasks are pods, then a pipeline would have to generate multiple pods. Let's check.

cat <<EOF > pipeHW.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: hello-pipeline
spec:
# Since pipeline uses tasks let's reuse the tasks we already have created
tasks: # Expects a list
- name: hello
taskRef: # Pointing to an existing task
name: hello-task

# We can create a task here directly
- name: finaltask
taskSpec: # Creating a new task on the fly defining inside the pipeline
steps:
- name: final-task
image: alpine
script: >
echo "final task finalizing"
EOF

k create -f pipeHW.yaml
pipeline.tekton.dev/hello-pipeline created

k get pipeline
NAME AGE
hello-pipeline 42s

# Even though we defined a task inside pipeline it wasn't created separately to be available.
# For reuse it's good to have tasks defined separately.
k get tasks
NAME AGE
hello-task 85m
hello-task2 65m


# To execute the pipeline we need the pipelineRun

cat <<EOF > pipeRunHW.yaml
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: hello-pipeline-
spec:
pipelineRef:
name: hello-pipeline
EOF

k get pipelinerun
NAME SUCCEEDED REASON STARTTIME COMPLETIONTIME
hello-pipeline-q5c4f True Succeeded 22s 13s

The pipeline is a controller for tasks, so it will create multiple task pods with the pipeline name in front.

# pods with the hello-task prefix were created earlier
k get pods | grep hello
hello-pipeline-q5c4f-finaltask-pod 0/1 Completed 0 100s
hello-pipeline-q5c4f-hello-pod 0/1 Completed 0 100s
hello-task-46z7v-pod 0/1 Completed 0 81m
hello-task2-fg8gh-pod 0/2 Completed 0 70m

k logs hello-pipeline-q5c4f-hello-pod
Defaulted container "step-hello" out of: step-hello, prepare (init), place-scripts (init)
Hello World

k logs hello-pipeline-q5c4f-finaltask-pod
Defaulted container "step-final-task" out of: step-final-task, prepare (init), place-scripts (init)
final task finalizing

The tip is to always build tasks that will become lego pieces to build a pipeline in the future.

Once again remembering that pipeline is also a namespace-level resource.

k get pipeline -n tekton-pipelines
No resources found in tekton-pipelines namespace.

k get pipeline -n default
NAME AGE
hello-pipeline 12m

Remembering tkn we have tkn pipeline.

tkn pipeline list
NAME AGE LAST RUN STARTED DURATION STATUS
hello-pipeline 26 minutes ago hello-pipeline-q5c4f 20 minutes ago 9s Succeeded

tkn pipeline list -n tekton-pipelines
No Pipelines found

tkn pipelinerun logs hello-pipeline-q5c4f
[finaltask : final-task] final task finalizing

[hello : hello] Hello World