Skip to content

Commit

Permalink
update pipeline-object-results example
Browse files Browse the repository at this point in the history
This commit updates the existinh pipeline-object-results example with
more checks and logging messages.

Signed-off-by: Yongxuan Zhang [email protected]
  • Loading branch information
Yongxuanzhang committed Feb 16, 2023
1 parent 62e808b commit 095f425
Showing 1 changed file with 37 additions and 27 deletions.
64 changes: 37 additions & 27 deletions examples/v1beta1/pipelineruns/alpha/pipeline-object-results.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pipelinerun-object-results
generateName: pipelinerun-object-results-
spec:
pipelineSpec:
tasks:
Expand All @@ -12,56 +12,66 @@ spec:
type: object
description: The object results
properties:
foo:
url:
type: string
hello:
digest:
type: string
steps:
- name: write-object
image: bash:latest
script: |
#!/usr/bin/env bash
echo -n "{\"foo\":\"bar\",\"hello\":\"world\"}" | tee $(results.object-results.path)
echo -n "{\"url\":\"abc.dev/sampler\",\"digest\":\"19f02276bf8dbdd62f069b922f10c65262cc34b710eea26ff928129a736be791\"}" | tee $(results.object-results.path)
- name: task2
params:
- name: whole-object
value: "$(tasks.task1.results.object-results[*])"
- name: object-element
value: "$(tasks.task1.results.object-results.hello)"
- name: object-url
value: "$(tasks.task1.results.object-results.url)"
taskSpec:
params:
- name: object-url
type: string
- name: whole-object
type: object
properties:
foo:
url:
type: string
hello:
digest:
type: string
default: {
hello: "",
foo: "",
}
- name: object-element
type: string
default: "defaultparam1"
steps:
- name: print-object-foo
- name: validate-object-url
image: bash:latest
args: [
"echo",
"$(params.whole-object.foo)"
"$(params.whole-object.url)"
]
- name: print-object-hello
script: |
if [[ $1 != "abc.dev/sampler" ]]; then
echo "failed to validate the one and only argument of the script"
echo "Want: abc.dev/sampler, Got: $1"
exit 1
else
echo "validate the object-url successfully"
fi
- name: validate-whole-object
image: ubuntu
script: |
#!/bin/bash
VALUE=$(params.object-element)
EXPECTED="world"
diff=$(diff <(printf "%s\n" "${VALUE[@]}") <(printf "%s\n" "${EXPECTED[@]}"))
if [[ -z "$diff" ]]; then
echo "Get expected: ${VALUE}"
exit 0
EXPECTED_url=abc.dev/sampler
EXPECTED_digest="19f02276bf8dbdd62f069b922f10c65262cc34b710eea26ff928129a736be791"
if [[ $(params.whole-object.url) != ${EXPECTED_url} ]]; then
echo "failed to validate the object"
echo "Want: ${EXPECTED_url}, Got: $(params.whole-object.url)"
exit 1
else
echo "validate the object url successfully"
fi
if [[ $(params.whole-object.digest) != ${EXPECTED_digest} ]]; then
echo "failed to validate the object"
echo "Want: ${EXPECTED_digest}, Got: $(params.whole-object.digest)"
exit 1
else
echo "Want: ${EXPECTED} Got: ${VALUE}"
exit 1
echo "validate the object digest successfully"
fi

0 comments on commit 095f425

Please sign in to comment.