@@ -49,30 +49,39 @@ spec:
4949 script : |
5050 #!/bin/sh
5151
52+ status="`echo $(params.status) | tr '[:upper:]' '[:lower:]'`"
53+
54+ # Exit early if deploy succeeded
55+ if [ "$status" = "succeeded" ]; then
56+ echo "Deploy succeeded, no failed tasks to analyze"
57+ exit 0
58+ fi
59+
5260 pipelinerun_name=$(awk -F= '$1 == "tekton.dev/pipelineRun" {gsub(/"/, "", $2); print $2}' /etc/podinfo/labels)
5361
5462 # Get names of taskRuns from the pipelineRun
5563 taskruns=$(kubectl -n ci get pipelinerun $pipelinerun_name -o json | jq -r '.status.childReferences[]?.name')
5664
57- # Get names of failed task and step from the taskRun
65+ # Get names of failed pod, task and step from the taskRuns
5866 for taskrun_name in $taskruns; do
5967 kubectl -n ci get taskrun $taskrun_name -o json |
6068 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)}' \
69+ { pod: .status.podName,
70+ task: .metadata.labels["tekton.dev/pipelineTask"],
71+ step: (.status.steps[]? | select(.terminated.reason == "Error" and (.terminationReason != "Skipped")) | .name)}' \
6272 >> $(results.failed_info.path)
6373 done
6474
6575 failed_pod_name=$(cat $(results.failed_info.path) | jq '.pod' -r)
6676 failed_task=$(cat $(results.failed_info.path) | jq '.task' -r)
6777 failed_step=$(cat $(results.failed_info.path) | jq '.step' -r)
6878
69- # Fetch logs and save info about the failed task
7079 if [ -n "$failed_pod_name" ] && [ -n "$failed_step" ]; then
80+ # Fetch logs and save info about the failed task
81+ echo "Fetching logs for failed task: ${failed_task}, step: ${failed_step}"
82+ curl -sk "https://tekton-logs-server.ci.svc.cluster.local/logs/ci/${failed_pod_name}/step-${failed_step}" | tail -c 1982 > $(results.logs.path)
7183 echo $failed_task > $(results.failed_task.path)
7284 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)"
7685 fi
7786
7887 - name : notification
0 commit comments