@@ -139,7 +139,8 @@ func (pp *PipelinesProvider) Run(ctx context.Context, f fn.Function) error {
139
139
}
140
140
141
141
if pr .Status .GetCondition (apis .ConditionSucceeded ).Status == corev1 .ConditionFalse {
142
- return fmt .Errorf ("function pipeline run has failed, please inspect logs of Tekton PipelineRun \" %s\" " , pr .Name )
142
+ message := getFailedPipelineRunLog (ctx , pr , pp .namespace )
143
+ return fmt .Errorf ("function pipeline run has failed with message: \n \n %s" , message )
143
144
}
144
145
145
146
kClient , err := knative .NewServingClient (pp .namespace )
@@ -251,3 +252,30 @@ func (pp *PipelinesProvider) watchPipelineRunProgress(pr *v1beta1.PipelineRun) e
251
252
252
253
return nil
253
254
}
255
+
256
+ // getFailedPipelineRunLog returns log message for a failed PipelineRun,
257
+ // returns log from a container where the failing TaskRun is running, if available.
258
+ func getFailedPipelineRunLog (ctx context.Context , pr * v1beta1.PipelineRun , namespace string ) string {
259
+ // Reason "Failed" usually means there is a specific failure in some step,
260
+ // let's find the failed step and try to get log directly from the container.
261
+ // If we are not able to get the container's log, we return the generic message from the PipelineRun.Status.
262
+ message := pr .Status .GetCondition (apis .ConditionSucceeded ).Message
263
+ if pr .Status .GetCondition (apis .ConditionSucceeded ).Reason == "Failed" {
264
+ for _ , t := range pr .Status .TaskRuns {
265
+ if t .Status .GetCondition (apis .ConditionSucceeded ).Status == corev1 .ConditionFalse {
266
+ for _ , s := range t .Status .Steps {
267
+ if s .Terminated != nil && s .Terminated .ExitCode == 1 {
268
+ podLogs , err := k8s .GetPodLogs (ctx , namespace , t .Status .PodName , s .ContainerName )
269
+ if err == nil {
270
+ return podLogs
271
+ }
272
+ return message
273
+ }
274
+ }
275
+
276
+ }
277
+ }
278
+ }
279
+
280
+ return message
281
+ }
0 commit comments