Use heredocs instead of jq.

This commit is contained in:
James Pace 2023-01-31 20:16:19 -05:00
parent fc6a3c9c63
commit b373fca18c
4 changed files with 101 additions and 13 deletions

View File

@ -0,0 +1,57 @@
# A pipeline to test the infrasture around calling pipelines.
---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
name: test-report-pipeline
namespace: j7s-ci
spec:
description: "A test pipeline."
workspaces:
- name: shared-data
description: Shared data.
- name: git-credentials
description: tekton git credentials
tasks:
- name: fetch-repo
workspaces:
- name: output
workspace: shared-data
- name: ssh-directory
workspace: git-credentials
params:
- name: url
value: ssh://git.jpace121.net:2222/tests/job-test
- name: branch
value: master
taskRef:
name: j7s-git-clone
- name: cat-readme
runAfter: ["fetch-repo"]
workspaces:
- name: source
workspace: shared-data
taskSpec:
workspaces:
- name: source
steps:
- image: docker.io/debian:bullseye-slim
script: |
set -x
cat $(workspaces.source.path)/README.md
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

View File

@ -0,0 +1,20 @@
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: test-report-pipeline-
namespace: j7s-ci
spec:
pipelineRef:
name: test-report-pipeline
workspaces:
- name: shared-data
volumeClaimTemplate:
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
- name: git-credentials
secret:
secretName: git-credentials

View File

@ -16,20 +16,29 @@ spec:
#!/usr/bin/env bash
set -e
function make_request {
cat <<EOF > request.json
{
"projectId": $(params.project-id),
"title": "Failed run: $(params.run-name).",
"description": "Build Failed!",
"confidential": false,
"milestoneIds": [],
"fields": {"Type": "Build Failure"}
}
EOF
}
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
make_request
curl -u tekton:$TEKTON_API_KEY \
-H "Content-Type: application/json" \
-d@request3.json \
-d@request.json \
$(params.feedback-url)/~api/issues
;;
esac

View File

@ -28,15 +28,17 @@ spec:
esac
# Make a comment on the PR.
echo '{"userId" : 1, "requestId" : 1, "content" : "",
"date" : ""}' > comment.json
cat comment.json | jq ".userId = $TEKTON_USER_ID" | jq . > comment1.json
cat comment1.json | jq ".requestId = $(params.pr-id)" | jq . > comment2.json
cat comment2.json | jq ".date = \"`date +"%Y-%m-%dT%H:%M:%S%:z"`\"" | jq . > comment3.json
cat comment3.json | jq ".content = \"$STATUS Tekton run: $(params.run-name).\"" | jq . > comment4.json
cat <<EOF > comment.json
{
"userId": $TEKTON_USER_ID,
"requestId": $(params.pr-id),
"date": "`date +"%Y-%m-%dT%H:%M:%S%:z"`",
"content": "$STATUS Tekton run: $(params.run-name)."
}
EOF
curl -u tekton:$TEKTON_API_KEY \
-H "Content-Type: application/json" \
-d@comment4.json \
-d@comment.json \
$(params.feedback-url)/~api/pull-request-comments
env:
- name: TEKTON_API_KEY