Dynamically pre-filled global variables when running manual CI/CD pipelines
Release notes
Problem: Since v13.7 gitlab allows global variables to be pre-defined and pre-filled in gitlab-ci.yml on root level. This allows developers to choose a pre-defined value for a variable from a dropdown list.
This is useful for static values, but not the best experience when values need to be generated dynamically from an external source, all the more when logic needs to be applied to extract those values (breaking down and filtering some complex json object to generate an array of options etc...)
In some use cases, user would like to choose multiple values for a single variable (checkbox)
Also, options for variable B could depend on value chosen for variable A
Solution:
Allow generating options with script keyword, using inline bash script, or script from a file
Allow multiple selection (checkbox)
Allow referenced variables (variable B is rendered based on variable A)
Intended users
DevOps engineers - as pipeline developer Softwear engineers - as edge user
User experience goal
Allow developers to run manual pipelines with dynamically generated list of variables and their respective values
Proposal
variables:
include: # Multiple sources are allowed (should be merged into a single property)
- # path to variables.yml in source code
- # relative path to another project in gitlab
- # url to external source
- name: # String (variable name)
displayName: # Optional - String (Readonly, variable name displayed in UI, defaults to name)
type: # String | Checkbox | Dropdown
defaultValue: # Optional - String (defaults to options[0]) | Array of strings (when type is Checkbox)
options: # String | Array of strings
- script: # bash script | script from file (must return string or array of strings)
description: # String
references: # other pre-defined variable which value is used to generate the options for this variable
filter | searchbox: # Boolean (whether to display searchbox or not)
Example for includes:
./variables/var1.yml
name: VAR_1
type: Dropdown
options:
- script: '/bin/bash ./var1.sh'
description: "please select a value"
references: 'VAR_2'
searchbox: true
./variables/var2.yml
name: VAR_2
type: Checkbox
options:
- script: '/bin/bash ./var2.sh'
description: "please select values"
searchbox: true
.gitlab-ci.yml
variables:
include:
- './variables/var1.yml'
- './variables/var2.yml'
should result with:
variables:
- name: VAR_1
type: Dropdown
options:
- script: '/bin/bash ./var1.sh'
description: "please select a value"
references: 'VAR_2'
searchbox: true
- name: VAR_2
type: Checkbox
options:
- script: '/bin/bash ./var2.sh'
description: "please select values"
searchbox: true