Skip to content

Use text interpolation in CI YAML loader

Avielle Wolfe requested to merge 433002-final-text-interpolation into master

What does this MR do and why?

This MR uses the new text interpolation flow to interpolate inputs in CI config. It introduces a ci_text_interpolation feature flag to protect CI pipeline processing in case of unexpected errors in the text interpolation. Text interpolation will allow us to introduce array type inputs and use !reference in interpolated CI configs.

#433002 (closed)

How to set up and validate locally

  1. Run Feature.enable(:ci_text_interpolation)
  2. In any project, create a file included.yml in the root directory. Give it this content:
spec:
  inputs:
    after_script:
    allow_failure:
      type: boolean
    cleanup:
    deploy_job_name:
    parallel:
      type: number
    test_script_name:
---
.scripts:
  rspec:
    - echo "Runs rspec"
  cleanup:
    - echo "$[[ inputs.cleanup ]]"

test_job:
  after_script: $[[ inputs.after_script ]]
  parallel: $[[ inputs.parallel ]]
  script: !reference [.scripts, "$[[ inputs.test_script_name ]]"]

$[[ inputs.deploy_job_name ]]:
  allow_failure: $[[ inputs.allow_failure ]]
  script: echo "deploy"
  1. In the project's .gitlab-ci.yml, include included.yml like this:

    include:
      - local: included.yml
        inputs:
          after_script: "!reference [.scripts, cleanup]"
          allow_failure: true
          cleanup: Cleanup things
          deploy_job_name: inputs_deploy
          parallel: 8
          test_script_name: rspec
  2. See that the configuration is valid. Save it and see that a pipeline is created as expected

Related to #433002 (closed)

Edited by Avielle Wolfe

Merge request reports