Tekton pipeline - start pipelinerun via kubernetes/openshift api

408 views Asked by At

Just wondering if there's a way to start a Tekton pipeline via the Kubernetes API. I know we can use Triggers or the tkn cli. But for my use-case, the API would be a better option. Is there a way to do that?

I'm using OpenShift, but can't find any reference in the API documentation.

2

There are 2 answers

0
Jonas On

wondering if there's a way to start a Tekton pipeline via the Kubernetes API

Yes, this is possible. You start a run of a pipeline by creating a PipelineRun custom resource.

If you want to do it with Go code, you can use the generated client, in a similar way as for other Kubernetes custom resources.

0
Marco On

If you have already defined your Pipeline resource you can start a PipelineRun by submitting a new resource with PipelineRef:

POST https://:6443/apis/tekton.dev/v1beta1/namespaces/namespace/pipelineruns

 {
    "apiVersion": "tekton.dev/v1beta1",
    "kind": "PipelineRun",
    "metadata": {
        "generation": 1,
        "name": "new-pipeline-20221221-1", //unique
        "namespace": "namespace"
    },
    "spec": {
        "pipelineRef":{
            "name": "name-of-pipeline" // name of pipeline
         }
    }
}