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

Task "script" blocks do not support array types for parameters #2374

Closed
ad22 opened this issue Apr 12, 2020 · 14 comments
Closed

Task "script" blocks do not support array types for parameters #2374

ad22 opened this issue Apr 12, 2020 · 14 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature.

Comments

@ad22
Copy link
Contributor

ad22 commented Apr 12, 2020

Expected Behavior

$params.arrayVar[*] is expanded when referenced in the script

Actual Behavior

Error from server (BadRequest): error when creating "my-task.yaml": admission webhook "validation.webhook.pipeline.tekton.dev" denied the request: validation failed: variable type invalid in "\echo \"$(params.arrayVar[*])\"\n" for step script: taskspec.steps.script

Steps to Reproduce the Problem

Task

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: test
spec:
  params:
  - name: arrayVar
    description: my array
    type: array
  steps:
  - name: test
    image: alpine:latest
    script: |
      echo "$(params.arrayVar[*])"

TaskRun

apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
  name: run
spec:
  taskRef:
    name: test
  params:
    - name: arrayVar
      value:
        - "a"
        - "b"
@imjasonh
Copy link
Member

/type feature

@ghost ghost added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 13, 2020
@ghost
Copy link

ghost commented Apr 13, 2020

Thanks for the report! We do document this though it's a little bit buried: https://github.com/tektoncd/pipeline/blob/master/docs/tasks.md#substituting-array-parameters

You must reference parameters of type array in a completely isolated string within a larger string array.

The script field is just a string rather than an array, so the substitution doesn't work here. Will keep this issue open as a feature request to support it though.

@ad22
Copy link
Contributor Author

ad22 commented Apr 13, 2020

The script field is just a string rather than an array, so the substitution doesn't work here. Will keep this issue open as a feature request to support it though.

@sbwsg That makes sense, I didn't immediately make the connection when going through that line. I will open a PR to call out the script field explicitly in the docs, if that's ok.

This will be good to have if it can be implemented safely. As a workaround for my current task, I've create a space separated string type, which is almost equivalent since I'd guess the array expansion would be into a space separated string anyway.

@ghost
Copy link

ghost commented Apr 13, 2020

the array expansion would be into a space separated string anyway

Interestingly this is one of the reasons that we don't support array expansion in strings - different use-cases expect different joining strings. In some cases space-separated is good, in others comma-separated would be preferable.

If you do decide to pursue this then I'd recommend soliciting feedback in one of our Working Group meetings.

Also, paging @skaegi here as well who looked into implementing JSONPath for our variable interpolation, which might have built-in syntax for this or otherwise provide a longer-term solution to this problem?

@skaegi
Copy link
Contributor

skaegi commented Apr 14, 2020

See #1463 -- sorry this is a pretty typical use-case and I'm really late on getting back to working on this after the beta.

@tekton-robot
Copy link
Collaborator

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

/close

Send feedback to tektoncd/plumbing.

@tekton-robot
Copy link
Collaborator

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close.

/lifecycle rotten

Send feedback to tektoncd/plumbing.

@tekton-robot
Copy link
Collaborator

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.

/lifecycle stale

Send feedback to tektoncd/plumbing.

@tekton-robot tekton-robot added the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Aug 14, 2020
@tekton-robot
Copy link
Collaborator

@tekton-robot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

/close

Send feedback to tektoncd/plumbing.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot added lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. and removed lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. labels Aug 14, 2020
@vdemeester
Copy link
Member

/remove-lifecycle rotten
/remove-lifecycle stale
/reopen

@tekton-robot
Copy link
Collaborator

@vdemeester: Reopened this issue.

In response to this:

/remove-lifecycle rotten
/remove-lifecycle stale
/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@tekton-robot tekton-robot reopened this Aug 17, 2020
@tekton-robot tekton-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Aug 17, 2020
@bobcatfish
Copy link
Collaborator

As @sbwsg explained this was by design (#2374 (comment)) if we want to change this, maybe we can open a separate issue to explore it?

@joaosilva15
Copy link
Contributor

I found a workaround for anyone that stumbles on this. You can pass the array in the args section and then use the args in the script. In the above case, it would look something like

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: test
spec:
  params:
  - name: arrayVar
    description: my array
    type: array
  steps:
  - name: test
    image: alpine:latest
    args: ["$(params.arrayVar[*])"]
    script: |
      echo "$@"

As per tekton documentation

A step can specify a script field, which contains the body of a script. That script is invoked as if it were stored inside the container image, and any args are passed directly to it.

@YevheniiPokhvalii
Copy link

I found a workaround for anyone that stumbles on this. You can pass the array in the args section and then use the args in the script. In the above case, it would look something like

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: test
spec:
  params:
  - name: arrayVar
    description: my array
    type: array
  steps:
  - name: test
    image: alpine:latest
    args: ["$(params.arrayVar[*])"]
    script: |
      echo "$@"

As per tekton documentation

A step can specify a script field, which contains the body of a script. That script is invoked as if it were stored inside the container image, and any args are passed directly to it.

Nice solution by may not be suitable in some cases.

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

No branches or pull requests

8 participants