Allow Project/Group level variables to be expanded in .gitlab-ci.yml "include" values
Problem to solve
Create a way for Projects to mimick the Gitlab include:template system using custom CI configurations hosted within the project itself.
Intended users
- Delaney (Development Team Lead)
- Sasha (Software Developer)
- Devon (DevOps Engineer)
- Sidney (Systems Administrator)
Further details
As a way of standardizing our CI/CD, we have begun to create our own internal CI "template" files which are intended to be included in individual repositories .gitlab-ci.yml files as-needed. In an attempt to mirror how the include:template system works with the pre-defined CI/CD configurations provided by Gitlab, we have created an internal project mimicking the https://gitlab.com/gitlab-org/gitlab-foss/tree/master/lib/gitlab/ci/templates project and are manually including individual files from it.
In order to make this process easier, the idea came to me to setup variables at the project levels that point to each individual CI configurations raw file link with the intention of being able to use the variable in the "include:remote" value which would be expanded out to the actual link to the file.
This way, we could effectively emulate the "include:template" system but with custom CI templates created internally.
Proposal
The project variable VER_EXP_CI_URL is set to https://git.company.com/awesome-project/CI/templates/raw/master/export-version-ci.yml
The file to be included contains the contents below:
before_script:
- export VERSION=$(cat ./VERSION)
In https://git.company.com/my-group/my-project/app-repo/blob/master/.gitlab-ci.yml, we would have the include added like the example below.
include:
- remote: "${VER_EXP_CI_URL}"
- remote: "${SOME_OTHER_INCLUDE}"
Permissions and Security
I'm not familiar with the CI Linting security/permissions system and whether or not the Linter is able to take into consideration the defined project variables while linting the CI configuration.
What does success look like, and how can we measure that?
Successful implementation would allow for project defined variables to be used as values in an include statement. This would allow projects to implement a custom CI include:template system.
What is the type of buyer?
This feature would be useful to all users and would be perfect as a core product feature.
Links / references
https://gitlab.com/help/ci/yaml/README#includetemplate
https://gitlab.com/gitlab-org/gitlab-foss/tree/master/lib/gitlab/ci/templates