Conditional includes in .gitlab-ci.yml file
<!-- The first section "Release notes" is required if you want to have your release post blog MR auto generated. Currently in BETA, details on the **release post item generator** can be found in the handbook: https://about.gitlab.com/handbook/marketing/blog/release-posts/#release-post-item-generator and this video: https://www.youtube.com/watch?v=rfn9ebgTwKg. The next four sections: "Problem to solve", "Intended users", "User experience goal", and "Proposal", are strongly recommended in your first draft, while the rest of the sections can be filled out during the problem validation or breakdown phase. However, keep in mind that providing complete and relevant information early helps our product team validate the problem and start working on a solution. -->
### Release notes
Include is one of the most popular keywords to use when writing a full CI/CD pipeline, if you are are building GitLab pipelines, you are probably using the include keyword in your pipeline configuration, as it allows you to bring external YAML configuration into your CI/CD pipeline, include is also using in Parent child and multi project pipeline, in this release we are allowing you to conditional your includes, so in a single pipeline you can decide when should or shouldn't include external CI/CD configuration, this will make your pipeline more dynamic
### Problem to solve
<!-- What problem do we solve? Try to define the who/what/why of the opportunity as a user story. For example, "As a (who), I want (what), so I can (why/value)." -->
As an engineer who builds CI/CD pipelines, I want to conditionally include job definitions so that I can build a more consistent and extendable library of CI jobs that can be shared across projects.
Currently, it's not possible to conditionally include jobs in CI/CD pipelines, which users may want to do in the event they have a library of shared job definitions. One of the biggest hurdles to this is YAML namespace collisions, which we currently address via [parent/child pipelines](https://docs.gitlab.com/ee/ci/parent_child_pipelines.html). While this solution, particularly dynamic child pipelines, does work, it's still difficult to implement a number of shared job definitions from a single source (i.e. one project that's used as a CI "library") across multiple projects.
I'm creating this on behalf of a customer, who I think raised some really good points in their ticket: https://gitlab.zendesk.com/agent/tickets/177222 (ZD internal only)
### Intended users
Personas are described at https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/
* [Devon (DevOps Engineer)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#devon-devops-engineer)
* [Sidney (Systems Administrator)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#sidney-systems-administrator)
* [Rachel (Release Manager)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#rachel-release-manager)
* [Simone (Software Engineer in Test)](https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/#simone-software-engineer-in-test)
### User experience goal
<!-- What is the single user experience workflow this problem addresses?
For example, "The user should be able to use the UI/API/.gitlab-ci.yml with GitLab to <perform a specific task>"
https://about.gitlab.com/handbook/engineering/ux/ux-research-training/user-story-mapping/ -->
The workflow to address is reusing jobs across multiple pipelines. The goal is to prevent namespace collisions by including those jobs only under certain circumstances rather than generating the job conditionally. It's a quality of life improvement - the current method isn't necessarily broken, but it introduces a lot of extra moving parts.
### Proposal
<!-- How are we going to solve the problem? Try to include the user journey! https://about.gitlab.com/handbook/journeys/#user-journey -->
The proposed syntax would look like this:
```
# file: /templates/common.gitlab-ci.yml
variables:
__TEMPLATES_COMMON_YML__: true
# file: /templates/docker/build.gitlab-ci.yml"
include:
- local: "/templates/common.gitlab-ci.yml"
rules:
- if: $__TEMPLATES_COMMON_YML__
when: never
```
This uses the familiar `rules` syntax along with `include`, which is readable and concise. As far as implementation, we already do something similar with `workflow`. The conditions here would be evaluated as part of the merging of the YAML, and the defined template would only be merged into the pipeline for processing if the rules evaluate to true.
### Further details
<!-- Include use cases, benefits, goals, or any other details that will help us understand the problem better. -->
### Permissions and Security
This would not impact permissions or security as far as I can tell. It's a feature enhancement that already has a set of well-defined permissions that wouldn't need to change.
### Documentation
<!-- See the Feature Change Documentation Workflow https://docs.gitlab.com/ee/development/documentation/workflow.html#for-a-product-change
* Add all known Documentation Requirements in this section. See https://docs.gitlab.com/ee/development/documentation/feature-change-workflow.html#documentation-requirements
* If this feature requires changing permissions, update the permissions document. See https://docs.gitlab.com/ee/user/permissions.html -->
### Availability & Testing
<!-- This section needs to be retained and filled in during the workflow planning breakdown phase of this feature proposal, if not earlier.
What risks does this change pose to our availability? How might it affect the quality of the product? What additional test coverage or changes to tests will be needed? Will it require cross-browser testing?
Please list the test areas (unit, integration and end-to-end) that needs to be added or updated to ensure that this feature will work as intended. Please use the list below as guidance.
* Unit test changes
* Integration test changes
* End-to-end test change
See the test engineering planning process and reach out to your counterpart Software Engineer in Test for assistance: https://about.gitlab.com/handbook/engineering/quality/test-engineering/#test-planning -->
Requires unit tests for the changes we're introducing/updating here. Integration and E2E tests not required.
### What does success look like, and how can we measure that?
<!--
Define both the success metrics and acceptance criteria. Note that success metrics indicate the desired business outcomes, while acceptance criteria indicate when the solution is working correctly. If there is no way to measure success, link to an issue that will implement a way to measure this.
Create tracking issue using the the Snowplow event tracking template. See https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/issue_templates/Snowplow%20event%20tracking.md
-->
### What is the type of buyer?
<!-- What is the buyer persona for this feature? See https://about.gitlab.com/handbook/marketing/product-marketing/roles-personas/buyer-persona/
In which enterprise tier should this feature go? See https://about.gitlab.com/handbook/product/pricing/#four-tiers -->
### Is this a cross-stage feature?
<!-- Communicate if this change will affect multiple Stage Groups or product areas. We recommend always start with the assumption that a feature request will have an impact into another Group. Loop in the most relevant PM and Product Designer from that Group to provide strategic support to help align the Group's broader plan and vision, as well as to avoid UX and technical debt. https://about.gitlab.com/handbook/product/#cross-stage-features -->
No, this is a highly specific feature enhancement to CI/CD and the verify stage.
### Links / references
<!-- Label reminders - you should have one of each of the following labels if you can figure out the correct ones -->
<!-- triage-serverless v3 PLEASE DO NOT REMOVE THIS SECTION -->
*This page may contain information related to upcoming products, features and functionality.
It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes.
Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.*
<!-- triage-serverless v3 PLEASE DO NOT REMOVE THIS SECTION -->
issue