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

TriggerTemplate unable to use JSON array as parameter #1562

Open
jangel97 opened this issue Mar 18, 2023 · 13 comments
Open

TriggerTemplate unable to use JSON array as parameter #1562

jangel97 opened this issue Mar 18, 2023 · 13 comments
Labels
area/roadmap Issues that are part of the project (or organization) roadmap (usually an epic) help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.

Comments

@jangel97
Copy link

Hi,

I am trying to trigger the creation of VMs using a tekton pipeline. The idea is that there is an eventlistener which receives a HTTP POST request with the data required for the provisioning.

This is an example of the JSON payload that I need to pass to the pipelinerun:

{
  "systems": [
    {
      "name": "vm1webserver",
      "os": "RHEL9",
      "vm size": "small",
      "network": "default",
      "namespace": "vm-webservers"
    },
    {
      "name": "vm2webserver",
      "os": "RHEL9",
      "vm size": "small",
      "network": "default",
      "namespace": "vm-webservers"
    },
  ]
}

I am unable to achieve to read an object parameter using TriggerTemplate

My tekton triggers look like this:

---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerBinding
metadata:
  name: provisioning-pipelinebinding
  namespace: tekton-vm-provisioning-pipeline
spec:
  params:
    - name: systems
      value: $(body.systems)
---
apiVersion: triggers.tekton.dev/v1alpha1
kind: TriggerTemplate
metadata:
  name: provisioning-automation-tt
  namespace: tekton-vm-provisioning-pipeline
  annotations:
    triggers.tekton.dev/old-escape-quotes: "true"
spec:
  params:
    - name: systems
  resourcetemplates:
    - apiVersion: tekton.dev/v1beta1
      kind: PipelineRun
      metadata:
        generateName: tekton-vm-provisioning-pipeline-
        labels:
          tekton.dev/pipeline: tekton-vm-provisioning-pipeline
        namespace: tekton-vm-provisioning-pipeline
      spec:
        params:
          - name: systems
            value: $(tt.params.systems)
        pipelineRef:
          name: vm-provisioning
        workspaces:
          - name: shared-workspace
            volumeClaimTemplate:
              metadata:
                annotations:
                  kubernetes.io/reclaimPolicy: Delete
                labels: {}
                name: ws-pvc
              spec:
                accessModes:
                  - ReadWriteMany
                resources:
                  requests:
                    storage: 500Mi
                storageClassName: managed-nfs-storage

My tekton pipeline:

---
apiVersion: tekton.dev/v1beta1
kind: Pipeline
metadata:
  name: vm-provisioning
spec:
  params:
    - name: systems
      type: array
  workspaces:
    - name: shared-workspace
  tasks:
    - name: get-cluster-info
      taskRef:
        name: get-cluster-info
      params:
        - name: names
          value: '$(params.systems[*])'
      workspaces:
        - name: source
          workspace: shared-workspace

When spawning pipeline I see following error:

PipelineRun tekton-vm-provisioning-pipeline/tekton-vm-provisioning-pipeline-jkv5k parameters have mismatching types with Pipeline tekton-vm-provisioning-pipeline/vm-provisioning's parameters: parameters have inconsistent types : [systems]

Is this supported in tekton?

Thanks,

@jangel97
Copy link
Author

I tried to parse JSON payload as string, and then use jq in the task to read json payload, I was not successful. Did anyone successfully achieved this?

@savitaashture
Copy link
Contributor

Something similar ask here #893

@savitaashture savitaashture added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 22, 2023
@savitaashture
Copy link
Contributor

Its not supported today
But its a good feature to add

@arjunsbabu43
Copy link

This is a much needed feature. Its very hard to fetch each parameter from a json payload.
In Jenkins we had something like multi line parameter. Not sure why ChatGpt is saying there is a type json.
image

@dibyom
Copy link
Member

dibyom commented Mar 23, 2023

hey @arjunsbabu43 Tekton pipelines does support object parameters as a beta feature but we have yet to build support for that in Triggers.

@dibyom dibyom added the area/roadmap Issues that are part of the project (or organization) roadmap (usually an epic) label Mar 23, 2023
@CPinhoK
Copy link

CPinhoK commented Apr 26, 2023

+1 for this feature

@aw185176
Copy link

Its not supported today
But its a good feature to add

This is much more than a good feature to add... at this point the triggers project is not compatible with the pipelines project at a fundamental level.

@dibyom dibyom added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label May 11, 2023
@dibyom
Copy link
Member

dibyom commented May 11, 2023

@khrm @savitaashture let's consider this for the next milestone?

@dibyom dibyom added this to the Triggers v0.25 milestone May 17, 2023
@arjunsbabu43
Copy link

Thank you, @dibyom. Do you have any information on the anticipated release date for Triggers v0.25?

@khrm
Copy link
Contributor

khrm commented Jul 17, 2023

A workaround for this is using CEL interceptor.
Something like this:

        - ref:
            name: "cel"
          params:
            - name: "overlays"
              value:
                - key: list
                  expression: "body.list.marshalJSON()"
      bindings:
      - name: list
        value: $(extensions.list)
      template:
        spec:
          params:
            - name: list
          resourcetemplates:
            - apiVersion: tekton.dev/v1beta1
              kind: TaskRun
              metadata:
                generateName: cel-trig-
              spec:
                taskSpec:
                  steps:
                  - image: ubuntu
                    script: |
                      #!/usr/bin/env bash
                      echo "SHA is : $(tt.params.list)"

@arjunsbabu43
Copy link

Thanks @khrm will have a try and will let you know the results

@khrm
Copy link
Contributor

khrm commented Oct 18, 2023

I will add the workaround to the docs in this release.

@khrm khrm added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Jan 24, 2024
@khrm khrm modified the milestones: Triggers v0.26, Triggers v0.27 Jan 24, 2024
@savitaashture
Copy link
Contributor

@khrm will create a PR with workaround in the doc for now as we are moving this issue to next milestone

@khrm khrm modified the milestones: Triggers v0.27, Triggers v0.28 May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/roadmap Issues that are part of the project (or organization) roadmap (usually an epic) help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. kind/feature Categorizes issue or PR as related to a new feature. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release.
Projects
None yet
Development

No branches or pull requests

7 participants