Use heredocs instead of jq.
This commit is contained in:
parent
fc6a3c9c63
commit
b373fca18c
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -16,20 +16,29 @@ spec:
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
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
|
case "$(params.status)" in
|
||||||
"Succeeded" | "Completed")
|
"Succeeded" | "Completed")
|
||||||
echo "Build was successful!"
|
echo "Build was successful!"
|
||||||
;;
|
;;
|
||||||
"Failed" | "None")
|
"Failed" | "None")
|
||||||
echo "Build failed. :("
|
echo "Build failed. :("
|
||||||
echo '{"projectId": 0, "title": "", "description": "Build Failed!",
|
make_request
|
||||||
"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 \
|
curl -u tekton:$TEKTON_API_KEY \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d@request3.json \
|
-d@request.json \
|
||||||
$(params.feedback-url)/~api/issues
|
$(params.feedback-url)/~api/issues
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
|
|
@ -28,15 +28,17 @@ spec:
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Make a comment on the PR.
|
# Make a comment on the PR.
|
||||||
echo '{"userId" : 1, "requestId" : 1, "content" : "",
|
cat <<EOF > comment.json
|
||||||
"date" : ""}' > comment.json
|
{
|
||||||
cat comment.json | jq ".userId = $TEKTON_USER_ID" | jq . > comment1.json
|
"userId": $TEKTON_USER_ID,
|
||||||
cat comment1.json | jq ".requestId = $(params.pr-id)" | jq . > comment2.json
|
"requestId": $(params.pr-id),
|
||||||
cat comment2.json | jq ".date = \"`date +"%Y-%m-%dT%H:%M:%S%:z"`\"" | jq . > comment3.json
|
"date": "`date +"%Y-%m-%dT%H:%M:%S%:z"`",
|
||||||
cat comment3.json | jq ".content = \"$STATUS Tekton run: $(params.run-name).\"" | jq . > comment4.json
|
"content": "$STATUS Tekton run: $(params.run-name)."
|
||||||
|
}
|
||||||
|
EOF
|
||||||
curl -u tekton:$TEKTON_API_KEY \
|
curl -u tekton:$TEKTON_API_KEY \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d@comment4.json \
|
-d@comment.json \
|
||||||
$(params.feedback-url)/~api/pull-request-comments
|
$(params.feedback-url)/~api/pull-request-comments
|
||||||
env:
|
env:
|
||||||
- name: TEKTON_API_KEY
|
- name: TEKTON_API_KEY
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue