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

Cannot pass array to spec.tasks[0].when[0].values #4061

Closed
jochen1234 opened this issue Jun 24, 2021 · 3 comments · Fixed by #4075
Closed

Cannot pass array to spec.tasks[0].when[0].values #4061

jochen1234 opened this issue Jun 24, 2021 · 3 comments · Fixed by #4075
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@jochen1234
Copy link

jochen1234 commented Jun 24, 2021

I am using Tekton in openshift 4.7 and want to the when clause in pipeline to have a dynamic list to switch off/on tasks. In my test both task should not run, but only the one with the hard coded list ["blue","yellow","green"] skips. Can someone guide to what to do. Thank you very much in advance.

Pipeline

---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: test
spec:
  workspaces:
    - name: psb-deployment-checkout
  params:
    - name: deployments
      type: array
      description: "array of deployment to do"
  tasks:
    - name: getpodno1
      taskRef:
        name: openshift-client
      params:
        - name: SCRIPT
          value: "oc get pods"
      when:
        - input: "red"
          operator: in
          values: ["blue","yellow","green"]
      workspaces:
        - name: output
          workspace: psb-deployment-checkout
    - name: getpodno2
      taskRef:
        name: openshift-client
      params:
        - name: SCRIPT
          value: "oc get pods"
      when:
        - input: "red"
          operator: in
          values: ["$(spec.params.deployments)"]
      workspaces:
        - name: output
          workspace: psb-deployment-checkout

PipelineRun

---
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
  name: testrun
spec:
  pipelineRef:
    name: test
  serviceAccountName: default
  params:
    - name: deployments
      value:
        - "green"
        - "yellow"
        - "blue"
  workspaces:
    - name: psb-deployment-checkout
      persistentVolumeClaim:
        claimName: psb-deployment-pvc
      subPath: git-checkout
@jochen1234 jochen1234 added the kind/bug Categorizes issue or PR as related to a bug. label Jun 24, 2021
@vdemeester
Copy link
Member

/cc @jerop @pritidesai

@pritidesai
Copy link
Member

pritidesai commented Jun 25, 2021

This is interesting and weird. So we use star operator [*] to expand the array parameter, something like:

"$(params.deployments[*])"

The way you have specified here is not even getting replaced (with extra spec):

               "whenExpressions": [
                    {
                        "input": "red",
                        "operator": "in",
                        "values": [
                            "$(spec.params.deployments)"
                        ]
                    }
                ]

And the using the start operator, fails at the validation since the $(params.deployments[*]) returns string instead of []string

values: "$(params.deployments[*])"
cannot decode incoming new object: json: cannot unmarshal string into Go struct field WhenExpression.spec.tasks.when.values of type []string

And using the start operator within square brackets values: ["$(params.deployments[*])"], fails at the validation:

variable type invalid in "$(params.deployments[*])": spec.tasks[0].when[0].values

This is a bug, we need to fix it and document the right usage.

Thanks @jochen1234 for reporting it.

@jochen1234
Copy link
Author

Thank you, fixing it. My Questing would be, how can I use such fix. I am using Tekton in OpenShift 4.7. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants