From 137a9fcb3a2aadeffd8551018bf15f1deaa55d29 Mon Sep 17 00:00:00 2001 From: James Pace Date: Sun, 4 Dec 2022 20:50:31 -0500 Subject: [PATCH] First pass at reporting failed jobs to onedev. --- images/Dockerfile_curl | 6 +++++ jobs/test-trigger-check.yaml | 8 +------ pipelines/test-pipeline.yaml | 17 ++++++++++++++- tasks/j7s-onedev-file-bug.yaml | 40 ++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 images/Dockerfile_curl create mode 100644 tasks/j7s-onedev-file-bug.yaml diff --git a/images/Dockerfile_curl b/images/Dockerfile_curl new file mode 100644 index 0000000..3c830ef --- /dev/null +++ b/images/Dockerfile_curl @@ -0,0 +1,6 @@ +FROM docker.io/debian:bullseye-slim + +RUN apt update -y && \ + apt install -y \ + curl \ + jq \ No newline at end of file diff --git a/jobs/test-trigger-check.yaml b/jobs/test-trigger-check.yaml index 8a52b91..fcc2827 100644 --- a/jobs/test-trigger-check.yaml +++ b/jobs/test-trigger-check.yaml @@ -7,17 +7,11 @@ spec: spec: containers: - name: test-trigger-check - image: docker.io/debian:bullseye-slim - env: - - name: http_proxy - value: http://squid-service:3128 + image: 192.168.1.128:8443/curl:latest command: ["bash"] args: - "-c" - >- - apt update -y && - apt upgrade -y && - apt install -y curl && curl -X POST http://el-test-pipeline-listener.default.svc.cluster.local:8080 -H 'Content-Type: application/json' -d '{}' restartPolicy: Never backoffLimit: 0 \ No newline at end of file diff --git a/pipelines/test-pipeline.yaml b/pipelines/test-pipeline.yaml index 57a87e0..9497ceb 100644 --- a/pipelines/test-pipeline.yaml +++ b/pipelines/test-pipeline.yaml @@ -38,4 +38,19 @@ spec: script: | set -x cat $(workspaces.source.path)/README.md - exit 0 + exit -1 + finally: + - name: notify-onedev + params: + - name: tekton-login-secret-name + value: onedev-api-key + - name: feedback-url + value: https://git.jpace121.net/ + - name: project-id + value: 9 + - name: run-name + value: $(context.pipelineRun.name) + - name: status + value: $(tasks.status) + taskRef: + name: j7s-onedev-file-bug diff --git a/tasks/j7s-onedev-file-bug.yaml b/tasks/j7s-onedev-file-bug.yaml new file mode 100644 index 0000000..7d400d0 --- /dev/null +++ b/tasks/j7s-onedev-file-bug.yaml @@ -0,0 +1,40 @@ +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: j7s-onedev-file-bug +spec: + params: + - name: tekton-login-secret-name + - name: feedback-url + - name: project-id + - name: run-name + - name: status + steps: + - image: 192.168.1.128:8443/curl:latest + script: | + #!/usr/bin/env bash + set -ex + + case "$(params.status)" in + "Succeeded" | "Completed") + echo "Build was successful!" + ;; + "Failed" | "None") + echo "Build failed. :(" + echo '{"projectId": 0, "title": "", "description": "Build Failed!", + "confidential": false, "milestoneIds": [], + "fields": {"Type": "Build Failure"} }' > request1.json + cat request1.json | jq ".projectId = $(params.project-id)" | jq . > request2.json + cat request2.json | jq ".title = \"Failed run: $(params.run-name).\" " | jq . > request3.json + curl -u tekton:$TEKTON_API_KEY \ + -H "Content-Type: application/json" \ + -d@request3.json \ + $(params.feedback-url)/~api/issues + ;; + esac + env: + - name: TEKTON_API_KEY + valueFrom: + secretKeyRef: + name: $(params.tekton-login-secret-name) + key: accesstoken \ No newline at end of file