Skip to content

feat: add structured JSON/YAML output for list commands - #3242

Open
arvindk-softwaredev wants to merge 1 commit into
tektoncd:mainfrom
arvindk-softwaredev:feat/structuredOutput-list-command
Open

feat: add structured JSON/YAML output for list commands#3242
arvindk-softwaredev wants to merge 1 commit into
tektoncd:mainfrom
arvindk-softwaredev:feat/structuredOutput-list-command

Conversation

@arvindk-softwaredev

@arvindk-softwaredev arvindk-softwaredev commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Part of #2850

Changes

Adds -o json and -o yaml to list commands so users can get machine-readable output instead of only the table view.

Supported resources:

  • Pipeline, Task, PipelineRun, TaskRun
  • EventListener, TriggerBinding, ClusterTriggerBinding, TriggerTemplate
  • CustomRun

JSON/YAML is an array of resource objects, not a Kubernetes List wrapper. Each item includes canonical apiVersion and kind. Empty results print [] / []. Invalid formats are rejected with an error. Default table output is unchanged.

Shared helpers live in pkg/formatted (PrintStructuredOutput, SetTypeMeta, IsStructured). Help text, generated docs, and man pages are updated. Unit tests cover structured output, empty lists, invalid formats, and help examples.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Run the code checkers with make check
  • Regenerate the manpages, docs and go formatting with make generated
  • Commit messages follow commit message best practices

See the contribution guide
for more details.

Release Notes

Add -o json and -o yaml support to list commands for pipelines, tasks, pipeline runs, task runs, event listeners, trigger bindings, cluster trigger bindings, trigger templates, and custom runs. Structured output is an array of resource objects (not a Kubernetes List wrapper).

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Sep 11, 2026
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign vdemeester after the PR has been reviewed.
You can assign the PR to them by writing /assign @vdemeester in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Sep 11, 2026
@arvindk-softwaredev
arvindk-softwaredev marked this pull request as draft September 11, 2026 13:51
@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 11, 2026
@arvindk-softwaredev
arvindk-softwaredev force-pushed the feat/structuredOutput-list-command branch from 801eef1 to 0149eb1 Compare September 11, 2026 14:57
Add -o json and -o yaml support to list commands for pipelines, tasks,
pipeline runs, task runs, event listeners, trigger bindings, cluster
trigger bindings, trigger templates, and custom runs. Structured output
is rendered as arrays of resource objects rather than Kubernetes List
wrappers. Update help examples, generated docs, man pages, and add
tests for structured, empty, invalid, and help output.

Signed-off-by: Arvind <arvkrish@redhat.com>
Assisted-by: Cursor Grok 4.6
@arvindk-softwaredev
arvindk-softwaredev force-pushed the feat/structuredOutput-list-command branch from 0149eb1 to bf00fb6 Compare September 11, 2026 16:33
@arvindk-softwaredev
arvindk-softwaredev marked this pull request as ready for review September 11, 2026 16:47
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Sep 11, 2026
@divyansh42
divyansh42 requested a balanced review from Copilot September 12, 2026 03:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Structured serialization bypasses the advertised managed-fields filtering behavior.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds machine-readable JSON/YAML array output to nine Tekton resource list commands while retaining table output.

Changes:

  • Adds shared structured-output and TypeMeta helpers.
  • Integrates array output across Pipeline, Task, run, trigger, and CustomRun commands.
  • Updates tests, golden files, command docs, and man pages.
File summaries
File Description
test/e2e/pipeline/pipeline_test.go Validates Pipeline JSON arrays.
pkg/formatted/output.go Adds structured-output helpers.
pkg/formatted/output_test.go Tests shared helpers.
pkg/cmd/triggertemplate/list.go Adds TriggerTemplate arrays.
pkg/cmd/triggertemplate/list_test.go Tests TriggerTemplate output.
pkg/cmd/triggerbinding/list.go Adds TriggerBinding arrays.
pkg/cmd/triggerbinding/list_test.go Tests TriggerBinding output.
pkg/cmd/taskrun/list.go Adds TaskRun arrays.
pkg/cmd/taskrun/list_test.go Tests TaskRun output.
pkg/cmd/task/testdata/TestTaskList_in_all_namespaces_with_output_yaml_flag.golden Updates Task YAML fixture.
pkg/cmd/task/list.go Adds Task arrays and examples.
pkg/cmd/task/list_test.go Tests Task output.
pkg/cmd/pipelinerun/list.go Adds PipelineRun arrays.
pkg/cmd/pipelinerun/list_test.go Tests PipelineRun output.
pkg/cmd/pipeline/testdata/TestPipelineList_output_json.golden Adds Pipeline JSON fixture.
pkg/cmd/pipeline/testdata/TestPipelineList_in_all_namespaces_with_output_yaml_flag.golden Updates Pipeline YAML fixture.
pkg/cmd/pipeline/list.go Adds Pipeline arrays and examples.
pkg/cmd/pipeline/list_test.go Tests Pipeline output.
pkg/cmd/eventlistener/list.go Adds EventListener arrays.
pkg/cmd/eventlistener/list_test.go Tests EventListener output.
pkg/cmd/customrun/list.go Adds CustomRun arrays.
pkg/cmd/customrun/list_test.go Tests CustomRun output.
pkg/cmd/clustertriggerbinding/list.go Adds cluster binding arrays.
pkg/cmd/clustertriggerbinding/list_test.go Tests cluster binding output.
docs/man/man1/tkn-triggertemplate-list.1 Documents structured examples.
docs/man/man1/tkn-triggerbinding-list.1 Documents structured examples.
docs/man/man1/tkn-taskrun-list.1 Documents structured examples.
docs/man/man1/tkn-task-list.1 Documents structured examples.
docs/man/man1/tkn-pipelinerun-list.1 Documents structured examples.
docs/man/man1/tkn-pipeline-list.1 Documents structured examples.
docs/man/man1/tkn-eventlistener-list.1 Documents structured examples.
docs/man/man1/tkn-customrun-list.1 Documents structured examples.
docs/man/man1/tkn-clustertriggerbinding-list.1 Documents structured examples.
docs/cmd/tkn_triggertemplate_list.md Adds JSON/YAML examples.
docs/cmd/tkn_triggerbinding_list.md Adds JSON/YAML examples.
docs/cmd/tkn_taskrun_list.md Adds JSON/YAML examples.
docs/cmd/tkn_task_list.md Adds JSON/YAML examples.
docs/cmd/tkn_pipelinerun_list.md Adds JSON/YAML examples.
docs/cmd/tkn_pipeline_list.md Adds JSON/YAML examples.
docs/cmd/tkn_eventlistener_list.md Adds JSON/YAML examples.
docs/cmd/tkn_customrun_list.md Adds JSON/YAML examples.
docs/cmd/tkn_clustertriggerbinding_list.md Adds JSON/YAML examples.
Review details
  • Files reviewed: 42/42 changed files
  • Comments generated: 1
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread pkg/formatted/output.go
func PrintStructuredOutput(w io.Writer, format string, obj interface{}) error {
switch NormalizeOutput(format) {
case OutputJSON:
data, err := json.MarshalIndent(obj, "", " ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants