Support custom branch for Custom CI Configuration Path
Problem to solve
ATM, it is only possible to use the default branch as a source for an external CI configuration:
If the CI configuration will be hosted in a different project within GitLab, the path must be relative to the root directory in the other project, with the group and project name added to the end:
- .gitlab-ci.yml@mygroup/another-project
- my/path/.my-custom-file.yml@mygroup/another-project
You cannot set a custom branch.
Intended users
Further details
It is a common practice to use your default branch e.g. master
as your main development branch and a seperate stable
or production
branch for production-ready code.
With the current options, you are not able to follow this branching system in a project if you want to set a CI configuration from this project for another project by changing the Custom CI configuration path
.
In addition to that, it is not possible to easily switch between branches which may be a useful feature to test CI configuration changes.
Proposal
If you want to include a file from another project in your CI configuration, you have the following options at the moment:
- Specify Project and File Path:
include: - project: 'my-group/my-project' file: '/templates/.gitlab-ci-template.yml'
- Specify Project, Branch/Ref and File Path
include: - project: 'my-group/my-project' ref: v1.0.0 file: '/templates/.gitlab-ci-template.yml'
We should support both ways for Custom CI configuration path
, too:
- Without Branch:
my/path/.my-custom-file.yml@mygroup/another-project
- With Branch:
my/path/.my-custom-file.yml@mygroup/another-project@production
Using this simple approach, we only need to check if one or two @
-symbols are present in the configuration string and split accordingly.
Current Code:
class ExternalProject < Source
def content
strong_memoize(:content) do
next unless external_project_path?
path_file, path_project = ci_config_path.split('@', 2)
YAML.dump('include' => [{ 'project' => path_project, 'file' => path_file }])
end
end
def source
:external_project_source
end
private
# Example: path/to/.gitlab-ci.yml@another-group/another-project
def external_project_path?
ci_config_path =~ /\A.+(yml|yaml)@.+\z/
end
end
We only have to adjust the regular expression and check for the count of @
-symbols.
It is also backwards compatible.
Permissions and Security
Access is already checked, not needed.
Documentation
We need to asjust the documentation of the Custom CI configuration path by describing both ways.
Testing
It is required to test if specifying another branch works correctly (should be the case, as it depends on the include feature) and if not specifying another branch does not break backwards compatibility.
What is the type of buyer?
As Custom CI configuration path
is currently in FOSS/CE, this should also be in FOSS/CE.
Links / References
Custom CI Configuration Path MR: !20179 (merged)