Skip to content

Commit

Permalink
updating an example PR with array results
Browse files Browse the repository at this point in the history
Updating a PR to validate the length of the array results including
each element in the array.

Also, added an example to validate an array when one of the elements is
empty string.

Signed-off-by: pritidesai <pdesai@us.ibm.com>
  • Loading branch information
pritidesai committed Feb 3, 2023
1 parent 8b80e76 commit d945634
Showing 1 changed file with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,56 +1,94 @@
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: pipelinerun-array-results
generateName: pipelinerun-write-and-read-array-results-
spec:
pipelineSpec:
tasks:
- name: task1
taskSpec:
results:
- name: array-results
# a list of images in array-result-1
- name: array-results-1
type: array
description: The array results
# a list of images in array-result-2
- name: array-results-2
type: array
description: The array results
steps:
- name: write-array
image: bash:latest
script: |
#!/usr/bin/env bash
echo -n "[\"1\",\"2\",\"3\"]" | tee $(results.array-results.path)
image1="abc.dev/sampler/busysample@sha256:19f02276bf8dbdd62f069b922f10c65262cc34b710eea26ff928129a736be791"
image2="ubuntu"
image3="xyz.dev/awesomeness/awesomeness"
echo -n "[\"$image1\", \"$image2\", \"$image3\"]" | tee $(results.array-results-1.path)
echo -n "[\"\", \"$image3\"]" | tee $(results.array-results-2.path)
- name: task2
params:
- name: foo
value: "$(tasks.task1.results.array-results[*])"
- name: bar
value: "$(tasks.task1.results.array-results[2])"
- name: images
value: "$(tasks.task1.results.array-results-1[*])"
- name: image-1
value: "$(tasks.task1.results.array-results-1[2])"
- name: image-2
value: "$(tasks.task1.results.array-results-2[1])"
taskSpec:
params:
- name: foo
- name: images
type: array
default:
- "defaultparam1"
- "defaultparam2"
- name: bar
- name: image-1
type: string
- name: image-2
type: string
default: "defaultparam1"
steps:
- name: print-foo
- name: validate-images
image: bash:latest
args: [
"echo",
"$(params.foo[*])"
"$(params.images[*])"
]
- name: print-bar
script: |
echo "Validating the length of the array parameter - images"
echo "The array parameter, array-param1 must have 3 elements"
if [[ $# != 3 ]]; then
exit 1
fi
echo "Done validating the length of the array parameter - images"
echo "Validating the first image"
if [[ $1 != "abc.dev/sampler/busysample@sha256:19f02276bf8dbdd62f069b922f10c65262cc34b710eea26ff928129a736be791" ]]; then
exit 1
fi
echo "Done validating the first image"
echo "Validating the second image"
if [[ $2 != "ubuntu" ]]; then
exit 1
fi
echo "Done validating the second image"
echo "Validating the third image"
if [[ $3 != "xyz.dev/awesomeness/awesomeness" ]]; then
exit 1
fi
echo "Done validating the third image"
- name: validate-image
image: ubuntu
script: |
#!/bin/bash
VALUE=$(params.bar)
EXPECTED=3
VALUE=$(params.image-1)
EXPECTED="xyz.dev/awesomeness/awesomeness"
diff=$(diff <(printf "%s\n" "${VALUE[@]}") <(printf "%s\n" "${EXPECTED[@]}"))
if [[ -z "$diff" ]]; then
echo "Get expected: ${VALUE}"
exit 0
echo "Got expected: ${VALUE}"
else
echo "Want: ${EXPECTED} Got: ${VALUE}"
exit 1
fi
echo "Validating reading from an array when earlier elements are empty"
if [[ $(params.image-2) != $EXPECTED ]]; then
exit 1
fi
echo "Done validating reading from an array"

0 comments on commit d945634

Please sign in to comment.