Skip to main content

Minha Primeira Pipeline

Sabendo que pipeline são tasks agrupadas vamos direto ao ponto. Se tasks são pods, então uma pipeline teria que gerar vários pods. Vamos conferir.

cat <<EOF > pipeHW.yaml
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: hello-pipeline
spec:
# Se pipeline usa tasks vamos reaproveitar as tasks que já temos criadas
tasks: # Espera uma lista
- name: hello
taskRef: # Apontando uma task existente
name: hello-task

# Podemos criar uma task aqui diretamente
- name: finaltask
taskSpec: # Criando uma nova task on the fly definindo dentro do 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

# Por mais que definimos uma task dentro de pipeline ela não foi criada separadamente para ficar disponível.
# Para reaproveitamento é bom ter as tasks definidas separadamente.
k get tasks
NAME AGE
hello-task 85m
hello-task2 65m


# Para executar o pipeline precisamos do 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

O pipeline é um controller para tasks, logo ele irá criar várias pods de tasks com o nome da pipeline na frente.

# pods com o prefixo hello-task foram criados anteriormente
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

A dica é sempre montar tasks que irão virar peças de lego para montar uma pipeline no futuro.

Mais uma vez lembrando que pipeline também é um recurso a nível de namespace.

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

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

Lembrando do tkn temos o 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