Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating an example pipelinerun with array indexing #6060

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,86 @@ spec:
value: '$(params.environments[0])'
- name: environment2
value: '$(params.environments[1])'
- name: environments
value: '$(params.environments[*])'
taskSpec:
params:
- name: environment1
type: string
- name: environment2
type: string
- name: environments
type: array
steps:
# this step should echo "staging"
- name: echo-params-1
image: bash:3.2
# args must be initialed to "staging"
- name: validate-environment1
image: bash:latest
args: [
"echo",
"$(params.environment1)",
]
# this step should echo "staging"
- name: echo-params-2
script: |
if [[ $# != 1 ]]; then
echo "failed to validate the length of the arguments"
echo "Want: 1, Got: $#"
exit 1
fi
if [[ $1 != "staging" ]]; then
echo "failed to validate the one and only argument of the script"
echo "Want: staging, Got: $1"
exit 1
fi
if [[ $(params.environments[2]) != "prod" ]]; then
echo "failed to validate indexing into an array param"
echo "Want: prod, Got: $(params.environments[2])"
fi
jerop marked this conversation as resolved.
Show resolved Hide resolved
# this step validates string param which must be set to an array element - qa
- name: validate-environment2
image: ubuntu
script: |
#!/bin/bash
VALUE=$(params.environment2)
EXPECTED="qa"
diff=$(diff <(printf "%s\n" "${VALUE[@]}") <(printf "%s\n" "${EXPECTED[@]}"))
if [[ -z "$diff" ]]; then
echo "Get expected: ${VALUE}"
echo "Got expected: ${VALUE}"
exit 0
else
echo "Want: ${EXPECTED} Got: ${VALUE}"
exit 1
fi
# this step validates an array param which must have three values
# also validates indexing into an array param
- name: validate-environments
image: bash:latest
args: [
"$(params.environments[*])",
]
script: |
if [[ $# != 3 ]]; then
echo "failed to validate the length of the arguments"
echo "Want: 3, Got: $#"
exit 1
fi
if [[ $(params.environments[0]) != "staging" ]]; then
echo "failed to validate the first array element while indexing into an array"
echo "Want: staging, Got: $(params.environments[0])"
exit 1
fi
if [[ $(params.environments[1]) != "qa" ]]; then
echo "failed to validate the second array element while indexing into an array"
echo "Want: qa, Got: $(params.environments[1])"
exit 1
fi
if [[ $(params.environments[2]) != "prod" ]]; then
echo "failed to validate the third array element while indexing into an array"
echo "Want: prod, Got: $(params.environments[2])"
fi

---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
name: deployrun
generateName: pipelinerun-param-array-indexing-
spec:
pipelineRef:
name: deploy
Expand Down