Skip to content

Allow predefined functions in CI config interpolation; add truncate fxn

Leaminn Ma requested to merge ci-interpolation-input-functions into master

What does this MR do and why?

This MR adds support for functions to be specified in the Ci interpolation block. The syntax supported is:

$[[ <access> | <func1> | <func2> | ... <funcN> ]]

where <access> specifies the value to retrieve (e.g. inputs.key) and funcX are optional functions that you can provide with or without arguments.

The truncate(<offset>,<length>) function was also created so that it can be used to test this implementation.

Resolves #409462 (closed) (Step 1) as well as Step 3 (#409462 (closed)).

How to set up and validate locally

  1. Enable the FF: Feature.enable(:ci_include_components).
  2. Create a component file with the following contents:

components/component-1/template.yml

spec:
  inputs:
    test:
      default: 012345678
---
test-job-1:
    script: echo $[[ inputs.test | truncate(1,3) ]]
  1. In the Pipeline editor, update the config with the following. (Adjust the component path as needed.)
include:
  - component: gdk.test:3000/group-a/project-6/components/component-1@master
  1. Observe that the Full configuration shows the input value truncated to 3 letters and offset by 1:

Screenshot_2023-07-07_at_8.30.57_PM

  1. You can also test the following scenarios:
Component Expected Result
Multiple functions: $[[ inputs.test | truncate(1, 7) | truncate(2,3) ]] Screenshot_2023-07-10_at_8.39.11_PM
Too many functions: $[[ inputs.test |f|f|f|f|f|f|f|f|f|f|f|f|f|f|f Screenshot_2023-07-10_at_8.40.01_PM
String values (they get converted to 0 value integer in the truncate function): $[[ inputs.test | truncate("foo","bar") ]] Screenshot_2023-07-10_at_8.42.44_PM
Too many arguments: $[[ inputs.test | truncate(1,3,5) ]] Screenshot_2023-07-17_at_6.17.41_PM
Too few arguments: $[[ inputs.test | truncate(3) ]] Screenshot_2023-07-17_at_6.17.41_PM
Invalid function pattern: $[[ inputs.test | truncate%(1,3) ]] Screenshot_2023-07-10_at_8.45.16_PM
Unknown function: $[[ inputs.test | undefined(1,3) ]] Screenshot_2023-07-10_at_8.45.51_PM
Multiple interpolation blocks: $[[ inputs.test | truncate(1, 7) | truncate(2,3) ]] and $[[ inputs.test | truncate(2,3) ]] Screenshot_2023-07-10_at_8.46.31_PM

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #409462 (closed)

Edited by Leaminn Ma

Merge request reports