tektoncd / pipeline

A cloud-native Pipeline resource.
https://tekton.dev
Apache License 2.0
8.45k stars 1.77k forks source link

Support using a PipelineTask in the Pipeline CRD to run other Pipelines the same way we run a Task (nest pipelines in pipelines) #2134

Open skaegi opened 4 years ago

skaegi commented 4 years ago

Pipelines group tasks together in a workflow. It would be incredibly useful to be able to re-use that mechanism to create sub-workflows.

Pipelines and Tasks both take Params, Workspaces, and generate Results so with a little work it should be possible to use a PipelineRef in place of a TaskRef when defining a Pipeline Task. For the other aspects required to generate a "sub"-PipelineRun these could be inherited from the parent PipelineRun.

Here's a basic example to illustrate syntax...

apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: pipeline-calling-pipeline
spec:
  params:
  - name: best-param-ever
  workspaces:
  - name: pipeline-ws1
  tasks:
  - name: pipeline-in-task-clothing
    pipelineRef:
      name: some-sub-pipeline
    workspaces:
    - name: sub-pipeline-ws0
      workspace: pipeline-ws1
  - name: regular-task
    taskRef:
      name: some-task
    params:
    - name: new-input
      value: $(tasks.pipeline-in-task-clothing.results.some-ouput)
    workspaces:
    - name: src
      workspace: pipeline-ws1
    runAfter:
    - pipeline-in-task-clothing

In a nutshell, other than using pipelineRef in-place of taskRef the definitions behave the same.

vdemeester commented 4 years ago

/kind feature

bobcatfish commented 4 years ago

pipeline-in-task-clothing

image

jlpettersson commented 4 years ago

Pipelines and Tasks both take Params, Workspaces, and generate Results so with a little work it should be possible to use a PipelineRef in place of a TaskRef when defining a Pipeline Task. For the other aspects required to generate a "sub"-PipelineRun these could be inherited from the parent PipelineRun.

I feel the use case is a bit unclear here. But I do have things that reminds me about this. E.g. The use-case I describe in https://github.com/tektoncd/pipeline/issues/2505#issue-608585765 - there I use (or "link") two PipelineRun and reuse the workspace volume.

On the other hand, I will have another use-case that also reminds a bit. But one fundamental difference is that I probably want to have it asynchronous. When talking about "linking" Pipelines or "chain", it may be done synchronous or asynchronous. That is also related to e.g. introducing asynchronous tasks - but I need to think about it more.

madbence commented 4 years ago

This feature would be really useful for us. eg. right now we have a task that can set the status on a given commit, and a task that can execute unit tests (eg. run npm test, etc.). We'd like to distribute a task/pipeline that can combine these (eg. set the commit to pending, run unit tests, set commit status to success/failure).

nested-pipeline

we'd like to provide to option to use set-status and run-unit-tests in a pipeline, and to be able to use a "higher-level" task, like "run-unit-tests-with-commit-status".

bobcatfish commented 4 years ago

Thanks for the use case @madbence this looks exactly along the lines we're thinking as well - just to double check, set-status sets the status of something like a GitHub check (or similar using non-GitHub)?

bobcatfish commented 4 years ago

oh and i forgot to post here some relevant links:

madbence commented 4 years ago

@bobcatfish exactly, set-status creates a commit status.

vdemeester commented 4 years ago

cc @mattmoor

bobcatfish commented 4 years ago

Tekton custom tasks would let us have this feature and more; planning to put this feature on hold until we have custom tasks and then we can decide if we want it as a top level feature or not.

tekton-robot commented 4 years ago

Stale issues rot after 30d of inactivity. Mark the issue as fresh with /remove-lifecycle rotten. Rotten issues close after an additional 30d of inactivity. If this issue is safe to close now please do so with /close.

/lifecycle rotten

Send feedback to tektoncd/plumbing.

tekton-robot commented 4 years ago

Rotten issues close after 30d of inactivity. Reopen the issue with /reopen. Mark the issue as fresh with /remove-lifecycle rotten.

/close

Send feedback to tektoncd/plumbing.

tekton-robot commented 4 years ago

@tekton-robot: Closing this issue.

In response to [this](https://github.com/tektoncd/pipeline/issues/2134#issuecomment-674244105): >Rotten issues close after 30d of inactivity. >Reopen the issue with `/reopen`. >Mark the issue as fresh with `/remove-lifecycle rotten`. > >/close > >Send feedback to [tektoncd/plumbing](https://github.com/tektoncd/plumbing). Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
vdemeester commented 4 years ago

/remove-lifecycle rotten /remove-lifecycle stale /reopen

tekton-robot commented 4 years ago

@vdemeester: Reopened this issue.

In response to [this](https://github.com/tektoncd/pipeline/issues/2134#issuecomment-674763461): >/remove-lifecycle rotten >/remove-lifecycle stale >/reopen Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
dbazhal commented 4 years ago

Couldn't this issue be done without custom tasks? We're in pain from disability to include pipelines into pipelines :) Problem is that we have to include task "run_pipeline" each time when we want to include pipeline inside pipeline. Each time such "incuded" pipeline fails, there is no easy way to find out why subpipeline failed, or what tasks it contained, etc.

JPEWdev commented 3 years ago

I also would really like support for running pipelines inside of pipelines. This is really useful for the case were you want some "super pipeline" that runs different variants of the same sub pipeline with different arguments (i.e. like a matrix/parameterized build from most other CI systems), provided that it can run all the sub-pipelines in parallel with different workspaces.

JPEWdev commented 3 years ago

I also would really like support for running pipelines inside of pipelines. This is really useful for the case were you want some "super pipeline" that runs different variants of the same sub pipeline with different arguments (i.e. like a matrix/parameterized build from most other CI systems), provided that it can run all the sub-pipelines in parallel with different workspaces.

Also I would like to point out that it would only really be useful if the subpipelines could be scheduled on different nodes. My (limited) understanding of tekton is that this might be difficult if the parent pipeline has to specify the workspace

dbazhal commented 3 years ago

Also I would like to point out that it would only really be useful if the subpipelines could be scheduled on different nodes. My (limited) understanding of tekton is that this might be difficult if the parent pipeline has to specify the workspace

agreed. Work with workspaces is sometimes pain, double pain if super-pipeline can't create ws, so Super-pipeline runs 1) task to create ws 2) each sub-pipeline with passing it workspace as argument 3) has to finish with task that deleted ws.

Also, i dont know how it could be done, but it would be better to aggregate sub-pipelines bodies into single pipelinerun. Creating separate pipeline run for each "sub"-pipeline makes it difficult to read logs of each task in each sub-pipeline(even more difficult with openshift tekton pipelines web-interface), it makes sub-pipelines execute slower(running pipelinerun isnt flash-fast itself, and it makes sometimes passing same arguments to each sub-pipeline a lot of copy-paste work.

bobcatfish commented 3 years ago

Quick update from my side: I am (at least!) very strongly in favor of this feature: I think it solves a lot of problems we have around expressing more complex error handling without adding a lot of complication to our API.

Couldn't this issue be done without custom tasks?

Theoretically it could - the coupling to custom tasks is more about the fact that custom tasks make this really easy to prototype; and make it so folks can start using Pipelines within Pipelines right away without us explicitly needing to add support upstream.

We basically just need someone to have the time to prototype + propose + drive this forward. I haven't had the time so I'll unassign myself for now.

jerop commented 3 years ago

/assign

HerrmannHinz commented 3 years ago

super helpful. would finally allow us to "chain" pipelines. plz 🙏

aelbarkani commented 3 years ago

+1 for this feature, very helpful for reusing pipelines !

tekton-robot commented 2 years ago

Issues go stale after 90d of inactivity. Mark the issue as fresh with /remove-lifecycle stale with a justification. Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with /close with a justification. If this issue should be exempted, mark the issue as frozen with /lifecycle frozen with a justification.

/lifecycle stale

Send feedback to tektoncd/plumbing.

jerop commented 2 years ago

/lifecycle frozen

TEP-0056: Pipelines in Pipelines Experimental Project

jerop commented 1 year ago

TEP-0056 proposing Pipelines in Pipelines is implementable - we welcome contributions in implementing it

https://github.com/tektoncd/community/blob/main/teps/0056-pipelines-in-pipelines.md

/help-wanted

EmmaMunley commented 1 year ago

Happy to start working on implementing TEP-0056.

/assign @EmmaMunley

ChrisPaul33 commented 1 year ago

Hi, there are any updates about the implementation of the feature?

pritidesai commented 1 year ago

Hi @ChrisPaul33, we have started implementing this feature. What API version are you currently using? Looking for some insight for - https://github.com/tektoncd/pipeline/pull/7055#discussion_r1298820844

ChrisPaul33 commented 1 year ago

Hello @pritidesai, we are currently using v1beta1. We are still trying to migrate to Tekton so migrating from v1beta1 to v1 for us won't be a big deal. I will try my best to look at #7055.

uqix commented 10 months ago

Is matrix with pipelineRef supported?