Skip to content

Add --log-failed flag to pipelinerun logs command#2920

Open
chmouel wants to merge 1 commit into
tektoncd:mainfrom
chmouel:add-log-failed-flag
Open

Add --log-failed flag to pipelinerun logs command#2920
chmouel wants to merge 1 commit into
tektoncd:mainfrom
chmouel:add-log-failed-flag

Conversation

@chmouel

@chmouel chmouel commented Jun 23, 2026

Copy link
Copy Markdown
Member

Changes

Add a --log-failed flag to tkn pipelinerun logs that filters output
to only show logs from failed TaskRuns, similar to how GitHub CLI (gh) shows failed job logs. see https://docs.github.com/en/actions/how-tos/monitor-workflows/use-workflow-run-logs#viewing-logs-with-github-cli

tkn pr logs my-pipeline-run --log-failed

Behavior

  • When --log-failed is set, only TaskRuns with ConditionFalse status are shown
  • When --log-failed is set and the PipelineRun is still running, the completed-logs path is used (skips --follow) so only already-failed TaskRuns appear
  • If no TaskRuns have failed, an informative error is returned
  • Composes with --task flag (intersection of both filters)

Submitter Checklist

Add --log-failed flag to `tkn pipelinerun logs` to show logs for failed tasks only

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jun 23, 2026
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 23, 2026
@chmouel chmouel force-pushed the add-log-failed-flag branch from 645e0bb to ff3075b Compare June 23, 2026 07:57
Add a --log-failed flag to `tkn pipelinerun logs` that filters output
to only show logs from failed TaskRuns, similar to how GitHub Actions
shows failed job logs.

When --log-failed is set and the PipelineRun is still running, the
completed-logs path is used so only TaskRuns that have already failed
are shown. If no TaskRuns have failed, an informative error is returned.
The flag composes with --task (intersection of both filters).

Signed-off-by: Chmouel Boudjnah <chmouel@chmouel.com>
Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>

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.

Pull request overview

Adds a new --log-failed flag to tkn pipelinerun logs to restrict output to logs from failed TaskRuns, wiring the option through log reader plumbing and documenting/testing the new behavior.

Changes:

  • Introduce --log-failed CLI flag and plumb it through LogOptions into the log Reader.
  • Filter PipelineRun TaskRuns to only those with ConditionFalse, and return an error when none have failed.
  • Add unit tests and update generated user docs (man page + markdown).

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/taskrun/taskrun.go Adds TaskRun filtering helper to keep only failed runs based on status conditions.
pkg/options/logs.go Extends LogOptions with a Failed boolean to carry the new flag through the stack.
pkg/log/reader.go Stores the Failed option on the log Reader.
pkg/log/pipeline_reader.go Uses failed to bypass live pipeline streaming and to filter ordered TaskRuns to failures only.
pkg/cmd/pipelinerun/logs.go Adds --log-failed flag and updates command examples/help text.
pkg/cmd/pipelinerun/logs_test.go Adds unit tests validating failed-only output and the “no failures” error case.
docs/man/man1/tkn-pipelinerun-logs.1 Documents the new --log-failed option and example usage in man output.
docs/cmd/tkn_pipelinerun_logs.md Documents the new --log-failed option and example usage in markdown docs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 88 to +92
if err := r.waitUntilAvailable(); err != nil {
return nil, nil, err
}

ordered, err := r.getOrderedTasks(pr)
ordered, trsMap, err := r.getOrderedTasks(pr)
Comment on lines +1404 to +1406
prlo := logOpts(prName, ns, cs, dc, fake.Streamer(fakeLogs), false, false, true)
prlo.Failed = true
output, _ := fetchLogs(prlo)
@tekton-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vdemeester

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 Jul 9, 2026
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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants