Skip to content

Fix number and boolean CI input types being cast to string

Avielle Wolfe requested to merge 434826-fix-boolean-and-number-type-inputs into master

What does this MR do and why?

Boolean and number input types are being cast to strings when interpolated using gsub. This causes them to unexpectedly show up as strings in the final CI config, breaking pipelines where they are expected to have their type preserved.

This commit fixes the bug by replacing the entire node with the input value when the interpolation block is the entire length of the node. In other cases, we can assume that the input is being inserted into a string, so it's safe for us to use gsub to cast the value to a string and perform the insertion.

Changelog: fixed

Issue: #434826 (closed)

How to set up and validate locally

  1. Create a file included.yml in the root directory of a project
    spec:
      inputs:
        allow_failure:
          type: boolean
        parallel:
          type: number
    
    ---
    
    test:
      allow_failure: $[[ inputs.allow_failure ]]
      parallel: $[[ inputs.parallel ]]
      script: 'echo "Settings - Parallel: $[[ inputs.parallel ]] Allow failure: $[[ inputs.allow_failure ]]"'
  2. Update the project's .gitlab-ci.yml to be:
    include:
      - local: included.yml
        inputs:
          allow_failure: true
          parallel: 2      
  3. Run a pipeline and see that the config works as expected
Edited by Avielle Wolfe

Merge request reports