@@ -49,23 +49,30 @@ spec:
4949 script : |
5050 #!/bin/sh
5151
52- pipelinerun_name=$(awk -F= '/tekton.dev\/pipelineRun/ {gsub(/"/, "", $2);print $2}' /etc/podinfo/labels)
52+ pipelinerun_name=$(awk -F= '$1 == "tekton.dev/pipelineRun" {gsub(/"/, "", $2); print $2}' /etc/podinfo/labels)
53+
54+ # Get names of taskRuns from the pipelineRun
55+ taskruns=$(kubectl -n ci get pipelinerun $pipelinerun_name -o json | jq -r '.status.childReferences[]?.name')
5356
54- # get failed info from pipelinerun name
55- kubectl -n ci get pipelinerun $pipelinerun_name -o json |
56- jq '[.status.taskRuns | to_entries[] | select ( .value.status.conditions[0].reason == "Failed") |
57- { task: .value.pipelineTaskName, pod: .value.status.podName, steps: .value.status.steps[] } |
58- select (.steps.terminated.reason == "Error")][0] | { task: .task, pod: .pod, step: .steps.name }' \
59- > $(results.failed_info.path)
57+ # Get names of failed task and step from the taskRun
58+ for taskrun_name in $taskruns; do
59+ kubectl -n ci get taskrun $taskrun_name -o json |
60+ jq -r 'select(.status.conditions[0].reason == "Failed") |
61+ { pod: .status.podName, task: .metadata.labels["tekton.dev/pipelineTask"], step: (.status.steps[]? | select(.terminated.reason == "Error") | .name)}' \
62+ >> $(results.failed_info.path)
63+ done
6064
6165 failed_pod_name=$(cat $(results.failed_info.path) | jq '.pod' -r)
6266 failed_task=$(cat $(results.failed_info.path) | jq '.task' -r)
6367 failed_step=$(cat $(results.failed_info.path) | jq '.step' -r)
6468
65- if [ "$failed_pod_name" != "null" ] && [ "$failed_step" != "null" ]; then
66- kubectl -n ci logs $failed_pod_name -c step-$failed_step | tail -c 1982 > $(results.logs.path)
69+ # Fetch logs and save info about the failed task
70+ if [ -n " $failed_pod_name" ] && [ -n "$failed_step" ]; then
6771 echo $failed_task > $(results.failed_task.path)
6872 echo $failed_step > $(results.failed_step.path)
73+
74+ echo "Fetching logs from: $logs_url"
75+ curl -sk "https://tekton-logs-server.ci.svc.cluster.local/logs/ci/${failed_pod_name}/step-${failed_step}" | tail -c 1982 > "$(results.logs.path)"
6976 fi
7077
7178 - name : notification
0 commit comments