Skip to content

Add type validation to inputs

Avielle Wolfe requested to merge 390458-input-type-validation into master

What does this MR do and why?

This MR adds type validation to CI inputs. The available types are string, number, and boolean. Inputs without an explicit type are type string by default, which preserves the existing un-typed behavior.

Screenshots or screen recordings

Included template

This CI configuration requires 3 inputs, one from each of the possible types.

Includable CI configuration with 3 inputs of different types

Error messages

This configuration passes a number to test_input when a string is expected.

Error message showing that a string is expected

This configuration passes a string to multiple when a number is expected.

Error message showing that a number is expected

This configuration passes a string to run_job when a boolean is expected.

Error message showing that a boolean is expected

This configuration passes incorrect values to all 3 inputs, so an error message is displayed for each

Configuration with error message for all 3 inputs

Working configuration

This configuration passes correct values to all 3 inputs

Configuration giving correct values to all inputs

The included job runs successfully, with this output

Screenshot_2023-06-28_at_15.29.41

How to set up and validate locally

  1. In a project, create a file included.yml with the following configuration:
    spec:
        inputs:
            test_input:
                type: string
            multiple:
                type: number
            run_job:
                type: boolean
    
    ---
    
    included_job:
        script:
            - echo "`expr 2 \* $[[ inputs.multiple ]]`"
            - echo $[[ inputs.test_input ]]
            - if [ $[[ inputs.run_job ]] = true ] ; then
                echo 'run_job input is true!' ;
              fi
  2. In the CI editor, add the following config
    include:
        local: included.yml  
        inputs:  
            test_input: STRING_HERE 
            multiple: NUMBER_HERE
            run_job: BOOLEAN_HERE
  3. Give invalid values to the inputs and see that you get accurate error messages
  4. Give valid values to the inputs and save the configuration
  5. Run a pipeline and see that included_job runs successfully

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 #390458 (closed)

Edited by Avielle Wolfe

Merge request reports