Skip to content

Commit

Permalink
reflect state of started pipeline/task when using --showlog
Browse files Browse the repository at this point in the history
- this change fixes an issue where using --showlog with tkn start pipeline/task does not return a non-zero value when  created taskrun/pipelinerun fails.
- refer #1820

Signed-off-by: Avinal Kumar <[email protected]>
  • Loading branch information
avinal committed Sep 6, 2023
1 parent a328616 commit a320107
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
18 changes: 17 additions & 1 deletion pkg/cmd/pipeline/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
"knative.dev/pkg/apis"
"net/http"
"os"
"strings"
Expand Down Expand Up @@ -414,7 +415,22 @@ func (opt *startOptions) startPipeline(pipelineStart *v1beta1.Pipeline) error {
Params: opt.cliparams,
AllSteps: false,
}
return prcmd.Run(runLogOpts)
if err = prcmd.Run(runLogOpts); err != nil {
return err
}

// Fetch the PipelineRun to get the PipelineRun status
prLatest, err := pipelinerun.GetPipelineRun(pipelineRunGroupResource, cs, prCreated.Name, prCreated.Namespace)
if err != nil {
return err
}

// If PipelineRun status is not Succeeded, print the PipelineRun status
if prLatest.Status.GetCondition(apis.ConditionSucceeded).IsFalse() {
return errors.New(fmt.Sprintf("Pipelinerun %s did not succeed", prLatest.Name))
}

return nil
}

func (opt *startOptions) getInput(pipeline *v1beta1.Pipeline) error {
Expand Down
18 changes: 17 additions & 1 deletion pkg/cmd/task/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,23 @@ func startTask(opt startOptions, args []string) error {
Params: opt.cliparams,
AllSteps: false,
}
return taskrun.Run(runLogOpts)

if err := taskrun.Run(runLogOpts); err != nil {
return err
}

// fetch the taskrun again to get the latest status
trLatest, err := traction.GetTaskRun(taskrunGroupResource, cs, trCreated.Name, trCreated.Namespace)
if err != nil {
return err
}

// check if the created taskrun succeed or not
if !trLatest.IsSuccessful() {
return errors.New(fmt.Sprintf("TaskRun %s did not succeed", trCreated.Name))
}

return nil
}

func printTaskRun(output string, s *cli.Stream, tr interface{}) error {
Expand Down

0 comments on commit a320107

Please sign in to comment.