Pass current pipeline variables through to be used by the include section of remote files
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
Summary
When we include a remote file and that remote file has include:rules:if using some variables, those variables are not available there. That's because, in the initial implementation it's thought that when you include a remote file, and you don't know what project this file is in. So, we decided not to pass any variables to remotely included files. We didn't need them before. However, right now, we need variables because they can be used in the include section.
Example
Let's say we have this config:
# .gitlab-ci.yml
# https://gitlab.com/furkanayhan/test-project/-/blob/2500de5bc81f6eaba9caa145c9f726699c6d1f6d/.gitlab-ci.yml
include:
- remote: https://gitlab.com/furkanayhan/test-project/-/raw/nested-include-with-remote/.tests.yml
rules:
- if: '$CI_PROJECT_NAME == "test-project"'
test1:
script: echo $CI_PROJECT_NAME
# .tests.yml
# https://gitlab.com/furkanayhan/test-project/-/blob/2500de5bc81f6eaba9caa145c9f726699c6d1f6d/.tests.yml
include:
- local: .other_tests.yml
rules:
- if: '$CI_PROJECT_NAME == "test-project"'
test2:
script: echo $CI_PROJECT_NAME
# .other_tests.yml
# https://gitlab.com/furkanayhan/test-project/-/blob/2500de5bc81f6eaba9caa145c9f726699c6d1f6d/.other_tests.yml
test3:
script: echo $CI_PROJECT_NAME
Result: https://gitlab.com/furkanayhan/test-project/-/pipelines/431194890
What happened here?
In the first rule, we successfully evaluated if: '$CI_PROJECT_NAME == "test-project"' and included the remote file .tests.yml. However, in the include part of .tests.yml, we didn't have access to any variable, so - if: '$CI_PROJECT_NAME == "test-project"' was evaluated to false.
This issue is created from an error, what happened here?
Actually, this used to cause an error because we tried to use variables even if we didn't have them. However, not-having-variables situation was handled in !73378 (merged), so no error has been raised since then.
Problem
In .tests.yml, which is included with remote, we try to use a variable $CI_PROJECT_NAME in the include:rules:if part. Variables are not available in the include part in remotely included files.
Solution
Make it so it can pass current pipeline variables through so they can be used by remote files defined in include reference.
