Skip to content

feat: added support for --output json and --output yaml for cancel command for pipelinerun and taskrun - #3241

Merged
tekton-robot merged 1 commit into
tektoncd:mainfrom
anwesha-palit-redhat:feat/SRVKP-13105
Sep 24, 2026
Merged

tekton-robot merged 1 commit into
tektoncd:mainfrom
anwesha-palit-redhat:feat/SRVKP-13105

Conversation

@anwesha-palit-redhat

@anwesha-palit-redhat anwesha-palit-redhat commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Changes

Added -o/--output flag to pipelinerun cancel and taskrun cancel.

  • On success, when --output json or --output yaml is set, prints a structured result instead of the plain-text message.
  • Default behavior (no --output flag) is unchanged — still prints PipelineRun cancelled:
  • Invalid --output values (e.g. csv) return a clear error:
./tkn pipelinerun cancel sleep-pipeline-run-1789013716850-r-x6zw6 -n cancel-test -o csv
Error: invalid output format "csv": must be json or yaml
  • Error paths (e.g. cancelling an already-finished run) still return plain error text regardless of --output, so failures are never mistaken for valid structured output:
./tkn pipelinerun cancel sleep-pipeline-run-1789013716850-r-54f56 -n cancel-test -o yaml
Error: failed to cancel PipelineRun sleep-pipeline-run-1789013716850-r-54f56: PipelineRun has already finished execution
  • Successful structured output examples:
$ tkn pipelinerun cancel sleep-pipeline-run-tgckv-r-6qfrb -o json
{
    "cancelled": [
        {
            "kind": "PipelineRun",
            "name": "sleep-pipeline-run-tgckv-r-6qfrb",
            "namespace": "cancel-test",
            "requestedStatus": "Cancelled"
        }
    ]
}
$ tkn taskrun cancel my-taskrun -o yaml
cancelled:
- kind: TaskRun
  name: my-taskrun
  namespace: cancel-test
  requestedStatus: Cancelled
  • Reuses the shared pkg/formatted.PrintStructuredOutput/IsStructured helpers; introduces a CancelResult{Kind, Name, Status} struct local to each command package.
  • Updated --help examples for both commands to demonstrate -o json/-o yaml usage.

Submitter Checklist

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

See [the contribution guide](https://github.com/tektoncd/cli/blob/master/CONTRIBUTING.md) for more details.

Release Notes

tkn pipelinerun cancel and tkn taskrun cancel now support --output json and --output yaml

Both commands accept a new -o/--output flag to print the cancellation result as structured JSON or YAML instead of plain text — useful for scripts, automation, and AI agents that need machine-readable output. Default (no --output flag) behavior is unchanged. An unsupported format (e.g. -o csv) returns a clear error.

@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 tekton-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 11, 2026
@anwesha-palit-redhat

anwesha-palit-redhat commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor Author

/hold

Note: This PR depends on pkg/formatted/output.go and pkg/formatted/output_test.go, which are shared with the list PR. Please review and merge the list PR first, since it introduces these shared files; this PR only adds new usage on top of them for cancel. Once list lands, this PR can be rebased and the shared-file diff here should disappear.

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 11, 2026
@chmouel
chmouel requested a balanced review from Copilot September 11, 2026 11:50
Comment thread pkg/formatted/output_test.go

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.

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.


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

@chmouel chmouel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 11, 2026
@divyansh42
divyansh42 requested a balanced review from Copilot September 12, 2026 03:03

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

Generated command documentation is stale, and SetTypeMeta does not support pointer slices as its generic API implies.

Get a fresh assessment by requesting another Copilot review.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread pkg/formatted/output.go Outdated
Comment thread pkg/cmd/pipelinerun/cancel.go
Comment thread pkg/cmd/taskrun/cancel.go
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 15, 2026
@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor Author

/unhold

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 16, 2026
@pratap0007

Copy link
Copy Markdown
Contributor

/approve

@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: pratap0007

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

The pull request process is described 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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 17, 2026
@divyansh42

divyansh42 commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

/hold

We might need to re-think on the output format to meet the k8s standards. We can remove the hold once we conculde the discussion

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 17, 2026
@anwesha-palit-redhat
anwesha-palit-redhat force-pushed the feat/SRVKP-13105 branch 2 times, most recently from 98e9e41 to 021f76e Compare September 22, 2026 05:35
@anwesha-palit-redhat

Copy link
Copy Markdown
Contributor Author

@vdemeester the format is now updated for -o yaml and -o json for the format mentioned here

@vdemeester

Copy link
Copy Markdown
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 23, 2026
@divyansh42
divyansh42 requested a balanced review from Copilot September 23, 2026 18:47

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.

Copilot review overview

🟡 Changes recommended

TaskRun structured output does not match the documented status contract, and the helper documentation contains stale API references.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 3 Low severity

Open (4)
Resolved since last review (1)

Comment thread pkg/cmd/taskrun/cancel.go
Comment thread pkg/formatted/output.go Outdated
@tekton-robot tekton-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. and removed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Sep 24, 2026
@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed lgtm Indicates that a PR is ready to be merged. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Sep 24, 2026
@divyansh42
divyansh42 requested a balanced review from Copilot September 24, 2026 04:54

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.

Copilot review overview

🔵 Needs a closer look

TaskRun reports an inaccurate requested status, and PipelineRun grace statuses lack structured-output test coverage.

Review effort: Balanced
Findings: None

Resolved since last review (4)

@divyansh42

Copy link
Copy Markdown
Member

/retest

@divyansh42

Copy link
Copy Markdown
Member

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 24, 2026
@divyansh42

Copy link
Copy Markdown
Member

/retest

@divyansh42

Copy link
Copy Markdown
Member

/lgtm

Thanks @anwesha-palit-redhat

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 24, 2026
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Sep 24, 2026
@divyansh42

Copy link
Copy Markdown
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Sep 24, 2026
@tekton-robot
tekton-robot merged commit e369266 into tektoncd:main Sep 24, 2026
18 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants