diff --git a/examples/v1beta1/pipelineruns/alpha/pipelinerun-param-array-indexing.yaml b/examples/v1beta1/pipelineruns/alpha/pipelinerun-param-array-indexing.yaml index ac8600ccc49..cad3a82e632 100644 --- a/examples/v1beta1/pipelineruns/alpha/pipelinerun-param-array-indexing.yaml +++ b/examples/v1beta1/pipelineruns/alpha/pipelinerun-param-array-indexing.yaml @@ -13,22 +13,40 @@ 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 + # this step validates string param which must be set to an array element - qa + - name: validate-environment2 image: ubuntu script: | #!/bin/bash @@ -36,17 +54,45 @@ spec: 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