kubernetespipelinecicdtekton

Tekton: How delete successful pipelineruns?


My aspired tekton usecase is simple:

I plan to do the cleanup in an initial cleanup-task. That seems better to me than annotation- or cronjob-approaches. As long as nothing new is built, nothing has to be deleted.

Direct approaches:

Indirect approaches (first filtering a list of podnames and then delete them - not elegant at all):

Do you have any better more elegant approaches? Thanks a lot!


Solution

  • For completeness, I paste here the kubectl/oc native command for those of us who do not have the tkn cli. Replace target-namespace as needed.

    Delete failed pipelineruns:

    kubectl -n target-namespace delete pipelinerun $(kubectl -n target-namespace get pipelinerun -o jsonpath='{range .items[?(@.status.conditions[*].status=="False")]}{.metadata.name}{"\n"}{end}')
    

    Delete successful pipelineruns:

    kubectl -n target-namespace delete pipelinerun $(kubectl -n target-namespace get pipelinerun -o jsonpath='{range .items[?(@.status.conditions[*].status=="True")]}{.metadata.name}{"\n"}{end}')