Uploaded image for project: 'OpenShift Pipelines'
  1. OpenShift Pipelines
  2. SRVKP-9118

Custom Params do not work in on-cel-expression

XMLWordPrintable

    • 3
    • False
    • Hide

      None

      Show
      None
    • False
    • Hide
      In addition to template expansion (`{{ param }}`), custom parameters defined in the Repository CR are available as CEL variables in the `on-cel-expression` annotation. This allows you to control which PipelineRuns are triggered based on repository-specific configuration.

      For example, with this Repository CR configuration:

      ```yaml
      apiVersion: pipelinesascode.tekton.dev/v1alpha1
      kind: Repository
      metadata:
        name: my-repo
      spec:
        url: "https://github.com/owner/repo"
        params:
          - name: enable_ci
            value: "true"
          - name: environment
            value: "staging"
      ```

      You can use these parameters directly in your PipelineRun's CEL expression:

      ```yaml
      apiVersion: tekton.dev/v1
      kind: PipelineRun
      metadata:
        name: my-pipeline
        annotations:
          pipelinesascode.tekton.dev/on-cel-expression: |
            event == "push" && enable_ci == "true" && environment == "staging"
      spec:
        # ... pipeline spec
      ```

      f you define a custom parameter with the same name as a standard CEL variable, the standard variable will
      take precedence in CEL expressions. Custom parameters should use unique names that don't conflict with
      built-in variables.

      `event_type` is also available as a PAC standard variable for cel evaluation.
      Show
      In addition to template expansion (`{{ param }}`), custom parameters defined in the Repository CR are available as CEL variables in the `on-cel-expression` annotation. This allows you to control which PipelineRuns are triggered based on repository-specific configuration. For example, with this Repository CR configuration: ```yaml apiVersion: pipelinesascode.tekton.dev/v1alpha1 kind: Repository metadata:   name: my-repo spec:   url: " https://github.com/owner/repo "   params:     - name: enable_ci       value: "true"     - name: environment       value: "staging" ``` You can use these parameters directly in your PipelineRun's CEL expression: ```yaml apiVersion: tekton.dev/v1 kind: PipelineRun metadata:   name: my-pipeline   annotations:     pipelinesascode.tekton.dev/on-cel-expression: |       event == "push" && enable_ci == "true" && environment == "staging" spec:   # ... pipeline spec ``` f you define a custom parameter with the same name as a standard CEL variable, the standard variable will take precedence in CEL expressions. Custom parameters should use unique names that don't conflict with built-in variables. `event_type` is also available as a PAC standard variable for cel evaluation.
    • Bug Fix
    • Proposed
    • 3
    • Pipelines Sprint CrookShank 42, Pipelines Sprint CrookShank 43, Pipelines Sprint CrookShank 44, Pipelines Sprint CrookShank 45

      Custom Params cannot be used in on-cel expressions with errors that appear to be bugs

      Given a Repository CR with a custom param like below:

      spec:
        params:
        - name: test_params
          value: "true"
      

      The following on-cel-expressions do not work:

      Using event_type == "push" && {{test_params == true}} results in the following error:

      CEL expression evaluation error: expression "event_type == \"push\" && true == true" check failed: ERROR: <input>:1:1: undeclared reference to 'event_type' (in container '')  | event_type == "push" && true == true  | ^
      

      Removing the curly braces from the custom-param results in a different error:

      CEL expression evaluation error: expression "event_type == \"push\" && test_params == true" check failed: ERROR: <input>:1:1: undeclared reference to 'event_type' (in container '')  | event_type == "push" && test_params == true  | ^ ERROR: <input>:1:25: undeclared reference to 'test_params' (in container '')  | event_type == "push" && test_params == true  | ........................^
      

      However if I remove the reference to event_type, using just the on-cel expression {{test_params == true}} then the pipelinerun is matched as expected...

      Workaround

      Prerequisites (if any, like setup, operators/versions):

      Steps to Reproduce

       # <steps>

       

      Actual results:

      Expected results:

      Reproducibility (Always/Intermittent/Only Once):

      Acceptance criteria: 

       

      Definition of Done:

      Build Details:

      Additional info (Such as Logs, Screenshots, etc):

       

       *

              rh-ee-akpant Akshay Pant
              rh-ee-athorp Andrew Thorp
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: