pipeline icon indicating copy to clipboard operation
pipeline copied to clipboard

Add support for `when` within `matrix.include`.

Open arewm opened this issue 1 year ago • 3 comments

Feature request

Using matrix.include is helpful for reducing duplication in pipeline definitions when there are specific parameter configurations that are needed. All possible parameter configuration are not, however, needed for all PipelineRuns. It would be beneficial if we could use parameters to configure which items in matrix.include are actually used for a PipelineRun.

Use case

As a user, I want to be able to customize my pipeline runs only using the pipeline parameters. If I do not need all configured matrix includes, I should not need to modify the pipeline definition.

Pipeline definition snippet (i.e. can be referenced using the git resolver):

    - name: build-containers-multi-platform
      matrix:
        include:
          - name: amd64
            params:
              - name: IMAGE
                value: $(params.output-image)-amd64
              - name: PLATFORM
                value: $(params.platform-amd64)
            when:
              - input: "amd64"
                operator: in
                values: "$(params.enabled-platforms[*])"
          - name: arm64
            params:
              - name: IMAGE
                value: $(params.output-image)-arm64
              - name: PLATFORM
                value: $(params.platform-arm64)
            when:
              - input: "arm64"
                operator: in
                values: "$(params.enabled-platforms[*])"
          - name: ppc64le
            params:
              - name: IMAGE
                value: $(params.output-image)-ppc64le
              - name: PLATFORM
                value: $(params.platform-ppc64le)
            when:
              - input: "ppc64le"
                operator: in
                values: "$(params.enabled-platforms[*])"
          - name: s390x
            params:
              - name: IMAGE
                value: $(params.output-image)-s390x
              - name: PLATFORM
                value: $(params.platform-s390x)
            when:
              - input: "s390x"
                operator: in
                values: "$(params.enabled-platforms[*])"

Pipeline run snippet (pipeline is not running properly on ppc64le or s390x, so we will disable them):

spec:
  params:
  - name: enabled-platforms
    value:
      - arm64
    - name: platform-arm64
      value: linux/arm64
    - name: platform-ppc64le
      value: linux-m4.xl/ppc64le
    - name: platform-s390x
      value: linux/s390x

arewm avatar Jul 25 '24 14:07 arewm

+1!

In case someone comes across this issue, this is a request to add support for the when attribute for the items in the matrix.includes list.

lcarva avatar Jul 25 '24 18:07 lcarva

/assign

chengjoey avatar Aug 18 '24 05:08 chengjoey

A small problem, when.values should be an array

when:
- input: "amd64"
  operator: in
  values: 
    - "$(params.enabled-platforms[*])"

chengjoey avatar Aug 18 '24 13:08 chengjoey