tektoncd / pipeline

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

Increase Task Reuse #7988

Open BoyChai opened 1 month ago

BoyChai commented 1 month ago

Feature request

It would be beneficial to introduce a taskRef option in the creation of a Task to facilitate the reuse of certain features of a Task where the variations may simply be one parameter, to avoid the complexity of repeatedly inputting parameters. For instance, in sending notifications, most of the server information may remain the same and the only difference would typically be the message content. Entering these parameters for every task creation is cumbersome. Of course, one can create a task with fixed values and then invoke this Task, but this approach may be too complicated for beginners. Additionally, if some tasks are installed from hub.tekton.dev, altering their YAML configurations could also necessitate an understanding of their internal purposes, thus involving a learning cost.

Use case

I hope

apiVersion: tekton.dev/v1
kind: Task
metadata:
  name: notice-host-1
spec:
  params:
    - name: server
      value: host.com
    - name: port
      value: 8080
    - name: token
      value: "xxxxxxxxxxxxxxxxxxxxxx"
    - name: msg
  taskRef:
    name: notice
AlanGreene commented 1 month ago

You can specify a default value for each param: https://tekton.dev/docs/pipelines/tasks/#default-value

If no value is provided for that param at runtime (via TaskRun / PipelineRun) then the default value is used.

Also if you're using Tekton Triggers you can specify param values in your TriggerTemplate / TriggerBinding to avoid the need to provide them each time.

BoyChai commented 1 month ago

You can specify a default value for each param: https://tekton.dev/docs/pipelines/tasks/#default-value

If no value is provided for that param at runtime (via TaskRun / PipelineRun) then the default value is used.

Also if you're using Tekton Triggers you can specify param values in your TriggerTemplate / TriggerBinding to avoid the need to provide them each time.

Although default values can be used to solve the problem I raised, some Task exist in hub.tekton.dev, and some ordinary users may have some learning costs to modify these values. Adding the features I mentioned would be more convenient for users to use

AlanGreene commented 1 month ago

You can also specify default values in your Pipeline, so consumers of the Pipeline do not need to be aware of the individual Task config, but can still override the values you provide if they wish.

BoyChai commented 1 month ago

You can also specify default values in your Pipeline, so consumers of the Pipeline do not need to be aware of the individual Task config, but can still override the values you provide if they wish.

If I set these duplicate values in the pipeline, I will need to configure certain parameters repeatedly for each of my multiple pipelines, which is too troublesome. I hope to configure the fixed values of the task task before creating the pipeline, so that the configuration of each pipeline will be very convenient for me