debian-mirror-gitlab/doc/development/pipelines.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

872 lines
50 KiB
Markdown
Raw Normal View History

2021-01-29 00:20:46 +05:30
---
stage: none
2021-03-11 19:13:27 +05:30
group: Engineering Productivity
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2019-12-04 20:38:33 +05:30
# Pipelines for the GitLab project
2021-11-18 22:05:49 +05:30
Pipelines for [`gitlab-org/gitlab`](https://gitlab.com/gitlab-org/gitlab) (as well as the `dev` instance's) is configured in the usual
2021-09-04 01:27:46 +05:30
[`.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab-ci.yml)
2019-12-04 20:38:33 +05:30
which itself includes files under
2021-09-04 01:27:46 +05:30
[`.gitlab/ci/`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/.gitlab/ci)
2019-12-04 20:38:33 +05:30
for easier maintenance.
2022-07-16 23:28:13 +05:30
We're striving to [dogfood](https://about.gitlab.com/handbook/engineering/development/principles/#dogfooding)
2021-09-30 23:02:18 +05:30
GitLab [CI/CD features and best-practices](../ci/yaml/index.md)
2019-12-04 20:38:33 +05:30
as much as possible.
2021-11-18 22:05:49 +05:30
## Minimal test jobs before a merge request is approved
2019-12-04 20:38:33 +05:30
2021-11-18 22:05:49 +05:30
**To reduce the pipeline cost and shorten the job duration, before a merge request is approved, the pipeline will run a minimal set of RSpec & Jest tests that are related to the merge request changes.**
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
After a merge request has been approved, the pipeline would contain the full RSpec & Jest tests. This will ensure that all tests
have been run before a merge request is merged.
2020-10-24 23:57:45 +05:30
2021-12-11 22:18:48 +05:30
### Overview of the GitLab project test dependency
To understand how the minimal test jobs are executed, we need to understand the dependency between
GitLab code (frontend and backend) and the respective tests (Jest and RSpec).
This dependency can be visualized in the following diagram:
```mermaid
flowchart LR
subgraph frontend
fe["Frontend code"]--tested with-->jest
end
subgraph backend
be["Backend code"]--tested with-->rspec
end
2022-08-13 15:12:31 +05:30
2021-12-11 22:18:48 +05:30
be--generates-->fixtures["frontend fixtures"]
fixtures--used in-->jest
```
In summary:
- RSpec tests are dependent on the backend code.
- Jest tests are dependent on both frontend and backend code, the latter through the frontend fixtures.
2021-11-18 22:05:49 +05:30
### RSpec minimal jobs
2020-10-24 23:57:45 +05:30
2021-11-18 22:05:49 +05:30
#### Determining related RSpec test files in a merge request
2020-10-24 23:57:45 +05:30
2021-11-18 22:05:49 +05:30
To identify the minimal set of tests needed, we use the [`test_file_finder` gem](https://gitlab.com/gitlab-org/ci-cd/test_file_finder), with two strategies:
2020-10-24 23:57:45 +05:30
2022-07-16 23:28:13 +05:30
- dynamic mapping from test coverage tracing (generated via the [`Crystalball` gem](https://github.com/toptal/crystalball))
2021-11-18 22:05:49 +05:30
([see where it's used](https://gitlab.com/gitlab-org/gitlab/-/blob/47d507c93779675d73a05002e2ec9c3c467cd698/tooling/bin/find_tests#L15))
- static mapping maintained in the [`tests.yml` file](https://gitlab.com/gitlab-org/gitlab/-/blob/master/tests.yml) for special cases that cannot
be mapped via coverage tracing ([see where it's used](https://gitlab.com/gitlab-org/gitlab/-/blob/47d507c93779675d73a05002e2ec9c3c467cd698/tooling/bin/find_tests#L12))
2020-10-24 23:57:45 +05:30
2021-11-18 22:05:49 +05:30
The test mappings contain a map of each source files to a list of test files which is dependent of the source file.
In the `detect-tests` job, we use this mapping to identify the minimal tests needed for the current merge request.
2022-11-25 23:54:43 +05:30
Later on in [the `rspec fail-fast` job](#fail-fast-job-in-merge-request-pipelines), we run the minimal tests needed for the current merge request.
2021-11-18 22:05:49 +05:30
#### Exceptional cases
In addition, there are a few circumstances where we would always run the full RSpec tests:
- when the `pipeline:run-all-rspec` label is set on the merge request
2022-11-25 23:54:43 +05:30
- when the `pipeline:run-full-rspec` label is set on the merge request, this label is assigned by triage automation when the merge request is approved by any reviewer
2022-07-23 23:45:48 +05:30
- when the merge request is created by an automation (for example, Gitaly update or MR targeting a stable branch)
2022-01-26 12:08:38 +05:30
- when the merge request is created in a security mirror
2022-07-23 23:45:48 +05:30
- when any CI configuration file is changed (for example, `.gitlab-ci.yml` or `.gitlab/ci/**/*`)
2021-11-18 22:05:49 +05:30
### Jest minimal jobs
#### Determining related Jest test files in a merge request
To identify the minimal set of tests needed, we pass a list of all the changed files into `jest` using the [`--findRelatedTests`](https://jestjs.io/docs/cli#--findrelatedtests-spaceseparatedlistofsourcefiles) option.
In this mode, `jest` would resolve all the dependencies of related to the changed files, which include test files that have these files in the dependency chain.
#### Exceptional cases
In addition, there are a few circumstances where we would always run the full Jest tests:
2021-12-11 22:18:48 +05:30
- when the `pipeline:run-all-jest` label is set on the merge request
2022-07-23 23:45:48 +05:30
- when the merge request is created by an automation (for example, Gitaly update or MR targeting a stable branch)
2022-01-26 12:08:38 +05:30
- when the merge request is created in a security mirror
2022-07-23 23:45:48 +05:30
- when any CI configuration file is changed (for example, `.gitlab-ci.yml` or `.gitlab/ci/**/*`)
- when any frontend "core" file is changed (for example, `package.json`, `yarn.lock`, `babel.config.js`, `jest.config.*.js`, `config/helpers/**/*.js`)
- when any vendored JavaScript file is changed (for example, `vendor/assets/javascripts/**/*`)
2021-11-18 22:05:49 +05:30
- when any backend file is changed ([see the patterns list for details](https://gitlab.com/gitlab-org/gitlab/-/blob/3616946936c1adbd9e754c1bd06f86ba670796d8/.gitlab/ci/rules.gitlab-ci.yml#L205-216))
2022-04-04 11:22:00 +05:30
### Fork pipelines
2022-11-25 23:54:43 +05:30
We run only the minimal RSpec & Jest jobs for fork pipelines, unless the `pipeline:run-all-rspec`
2022-07-16 23:28:13 +05:30
label is set on the MR. The goal is to reduce the CI/CD minutes consumed by fork pipelines.
2022-04-04 11:22:00 +05:30
See the [experiment issue](https://gitlab.com/gitlab-org/quality/team-tasks/-/issues/1170).
2021-11-18 22:05:49 +05:30
## Fail-fast job in merge request pipelines
To provide faster feedback when a merge request breaks existing tests, we are experimenting with a
fail-fast mechanism.
An `rspec fail-fast` job is added in parallel to all other `rspec` jobs in a merge
request pipeline. This job runs the tests that are directly related to the changes
in the merge request.
If any of these tests fail, the `rspec fail-fast` job fails, triggering a
`fail-pipeline-early` job to run. The `fail-pipeline-early` job:
- Cancels the currently running pipeline and all in-progress jobs.
- Sets pipeline to have status `failed`.
For example:
```mermaid
graph LR
subgraph "prepare stage";
A["detect-tests"]
end
subgraph "test stage";
B["jest"];
C["rspec migration"];
D["rspec unit"];
E["rspec integration"];
F["rspec system"];
G["rspec fail-fast"];
end
subgraph "post-test stage";
Z["fail-pipeline-early"];
end
A --"artifact: list of test files"--> G
G --"on failure"--> Z
```
The `rspec fail-fast` is a no-op if there are more than 10 test files related to the
merge request. This prevents `rspec fail-fast` duration from exceeding the average
`rspec` job duration and defeating its purpose.
This number can be overridden by setting a CI/CD variable named `RSPEC_FAIL_FAST_TEST_FILE_COUNT_THRESHOLD`.
2022-11-25 23:54:43 +05:30
## Faster feedback when reverting merge requests
When you need to revert a merge request, to get accelerated feedback, you can add the `~pipeline:revert` label to your merge request.
When this label is assigned, the following steps of the CI/CD pipeline are skipped:
- The `e2e:package-and-test` job.
- The `rspec:undercoverage` job.
- The entire [Review Apps process](testing_guide/review_apps.md).
Apply the label to the merge request, and run a new pipeline for the MR.
2021-11-18 22:05:49 +05:30
## Test jobs
We have dedicated jobs for each [testing level](testing_guide/testing_levels.md) and each job runs depending on the
changes made in your merge request.
If you want to force all the RSpec jobs to run regardless of your changes, you can add the `pipeline:run-all-rspec` label to the merge request.
WARNING:
Forcing all jobs on docs only related MRs would not have the prerequisite jobs and would lead to errors
### Test suite parallelization
Our current RSpec tests parallelization setup is as follows:
1. The `retrieve-tests-metadata` job in the `prepare` stage ensures we have a
`knapsack/report-master.json` file:
- The `knapsack/report-master.json` file is fetched from the latest `main` pipeline which runs `update-tests-metadata`
2022-08-13 15:12:31 +05:30
(for now it's the 2-hourly `maintenance` scheduled master pipeline), if it's not here we initialize the file with `{}`.
2022-07-16 23:28:13 +05:30
1. Each `[rspec|rspec-ee] [migration|unit|integration|system|geo] n m` job are run with
2021-11-18 22:05:49 +05:30
`knapsack rspec` and should have an evenly distributed share of tests:
- It works because the jobs have access to the `knapsack/report-master.json`
since the "artifacts from all previous stages are passed by default".
- the jobs set their own report path to
`"knapsack/${TEST_TOOL}_${TEST_LEVEL}_${DATABASE}_${CI_NODE_INDEX}_${CI_NODE_TOTAL}_report.json"`.
- if knapsack is doing its job, test files that are run should be listed under
`Report specs`, not under `Leftover specs`.
1. The `update-tests-metadata` job (which only runs on scheduled pipelines for
[the canonical project](https://gitlab.com/gitlab-org/gitlab) takes all the
2022-07-16 23:28:13 +05:30
`knapsack/rspec*.json` files and merge them all together into a single
2021-11-18 22:05:49 +05:30
`knapsack/report-master.json` file that is saved as artifact.
After that, the next pipeline uses the up-to-date `knapsack/report-master.json` file.
2021-12-11 22:18:48 +05:30
### Flaky tests
2022-04-04 11:22:00 +05:30
#### Automatic skipping of flaky tests
2022-03-02 08:16:31 +05:30
Tests that are [known to be flaky](testing_guide/flaky_tests.md#automatic-retries-and-flaky-tests-detection) are
skipped unless the `$SKIP_FLAKY_TESTS_AUTOMATICALLY` variable is set to `false` or if the `~"pipeline:run-flaky-tests"`
label is set on the MR.
2021-12-11 22:18:48 +05:30
2022-04-04 11:22:00 +05:30
See the [experiment issue](https://gitlab.com/gitlab-org/quality/team-tasks/-/issues/1069).
#### Automatic retry of failing tests in a separate process
2022-06-21 17:19:12 +05:30
Unless `$RETRY_FAILED_TESTS_IN_NEW_PROCESS` variable is set to `false` (`true` by default), RSpec tests that failed are automatically retried once in a separate
2022-04-04 11:22:00 +05:30
RSpec process. The goal is to get rid of most side-effects from previous tests that may lead to a subsequent test failure.
We keep track of retried tests in the `$RETRIED_TESTS_REPORT_FILE` file saved as artifact by the `rspec:flaky-tests-report` job.
See the [experiment issue](https://gitlab.com/gitlab-org/quality/team-tasks/-/issues/1148).
2022-05-07 20:08:51 +05:30
### Single database testing
By default, all tests run with [multiple databases](database/multiple_databases.md).
We also run tests with a single database in nightly scheduled pipelines, and in merge requests that touch database-related files.
If you want to force tests to run with a single database, you can add the `pipeline:run-single-db` label to the merge request.
2021-11-18 22:05:49 +05:30
### Monitoring
The GitLab test suite is [monitored](performance.md#rspec-profiling) for the `main` branch, and any branch
that includes `rspec-profile` in their name.
### Logging
2022-10-11 01:57:18 +05:30
- Rails logging to `log/test.log` is disabled by default in CI
[for performance reasons](https://jtway.co/speed-up-your-rails-test-suite-by-6-in-1-line-13fedb869ec4).
2022-08-27 11:52:29 +05:30
To override this setting, provide the
2021-11-18 22:05:49 +05:30
`RAILS_ENABLE_TEST_LOG` environment variable.
## Review app jobs
Consult the [Review Apps](testing_guide/review_apps.md) dedicated page for more information.
2021-12-11 22:18:48 +05:30
If you want to force a Review App to be deployed regardless of your changes, you can add the `pipeline:run-review-app` label to the merge request.
2021-11-18 22:05:49 +05:30
## As-if-FOSS jobs
The `* as-if-foss` jobs run the GitLab test suite "as if FOSS", meaning as if the jobs would run in the context
2022-04-04 11:22:00 +05:30
of `gitlab-org/gitlab-foss`. These jobs are only created in the following cases:
2021-11-18 22:05:49 +05:30
- when the `pipeline:run-as-if-foss` label is set on the merge request
- when the merge request is created in the `gitlab-org/security/gitlab` project
2022-07-23 23:45:48 +05:30
- when any CI configuration file is changed (for example, `.gitlab-ci.yml` or `.gitlab/ci/**/*`)
2021-11-18 22:05:49 +05:30
The `* as-if-foss` jobs are run in addition to the regular EE-context jobs. They have the `FOSS_ONLY='1'` variable
set and get the `ee/` folder removed before the tests start running.
2022-04-04 11:22:00 +05:30
The intent is to ensure that a change doesn't introduce a failure after `gitlab-org/gitlab` is synced to `gitlab-org/gitlab-foss`.
2021-11-18 22:05:49 +05:30
## As-if-JH jobs
2022-08-27 11:52:29 +05:30
NOTE:
This is disabled for now.
2021-11-18 22:05:49 +05:30
The `* as-if-jh` jobs run the GitLab test suite "as if JiHu", meaning as if the jobs would run in the context
2022-04-04 11:22:00 +05:30
of [GitLab JH](jh_features_review.md). These jobs are only created in the following cases:
2021-11-18 22:05:49 +05:30
- when the `pipeline:run-as-if-jh` label is set on the merge request
- when the `pipeline:run-all-rspec` label is set on the merge request
- when any code or backstage file is changed
- when any startup CSS file is changed
The `* as-if-jh` jobs are run in addition to the regular EE-context jobs. The `jh/` folder is added before the tests start running.
2022-04-04 11:22:00 +05:30
The intent is to ensure that a change doesn't introduce a failure after `gitlab-org/gitlab` is synced to [GitLab JH](https://jihulab.com/gitlab-cn/gitlab).
2021-11-18 22:05:49 +05:30
2022-07-16 23:28:13 +05:30
### When to consider applying `pipeline:run-as-if-jh` label
2022-08-27 11:52:29 +05:30
NOTE:
This is disabled for now.
2022-07-16 23:28:13 +05:30
If a Ruby file is renamed and there's a corresponding [`prepend_mod` line](jh_features_review.md#jh-features-based-on-ce-or-ee-features),
it's likely that GitLab JH is relying on it and requires a corresponding
change to rename the module or class it's prepending.
2022-03-02 08:16:31 +05:30
### Corresponding JH branch
2022-08-27 11:52:29 +05:30
NOTE:
This is disabled for now.
2022-04-04 11:22:00 +05:30
You can create a corresponding JH branch on [GitLab JH](https://jihulab.com/gitlab-cn/gitlab) by
2022-03-02 08:16:31 +05:30
appending `-jh` to the branch name. If a corresponding JH branch is found,
`* as-if-jh` jobs grab the `jh` folder from the respective branch,
2022-07-16 23:28:13 +05:30
rather than from the default branch `main-jh`.
2022-03-02 08:16:31 +05:30
2022-04-04 11:22:00 +05:30
NOTE:
2022-05-07 20:08:51 +05:30
For now, CI will try to fetch the branch on the [GitLab JH mirror](https://gitlab.com/gitlab-org/gitlab-jh-mirrors/gitlab), so it might take some time for the new JH branch to propagate to the mirror.
2022-04-04 11:22:00 +05:30
2022-08-13 15:12:31 +05:30
## Ruby 3.0 jobs
You can add the `pipeline:run-in-ruby3` label to the merge request to switch
the Ruby version used for running the whole test suite to 3.0. When you do
this, the test suite will no longer run in Ruby 2.7 (default), and an
additional job `verify-ruby-2.7` will also run and always fail to remind us to
remove the label and run in Ruby 2.7 before merging the merge request.
This should let us:
- Test changes for Ruby 3.0
- Make sure it will not break anything when it's merged into the default branch
2022-01-26 12:08:38 +05:30
## `undercover` RSpec test
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/74859) in GitLab 14.6.
The `rspec:undercoverage` job runs [`undercover`](https://rubygems.org/gems/undercover)
to detect, and fail if any changes introduced in the merge request has zero coverage.
2022-04-04 11:22:00 +05:30
The `rspec:undercoverage` job obtains coverage data from the `rspec:coverage`
2022-01-26 12:08:38 +05:30
job.
In the event of an emergency, or false positive from this job, add the
`pipeline:skip-undercoverage` label to the merge request to allow this job to
fail.
2022-07-23 23:45:48 +05:30
### Troubleshooting `rspec:undercoverage` failures
2022-05-07 20:08:51 +05:30
2022-07-23 23:45:48 +05:30
The `rspec:undercoverage` job has [known bugs](https://gitlab.com/groups/gitlab-org/-/epics/8254)
2022-08-13 15:12:31 +05:30
that can cause false positive failures. You can test coverage locally to determine if it's
2022-07-23 23:45:48 +05:30
safe to apply `~"pipeline:skip-undercoverage"`. For example, using `<spec>` as the name of the
test causing the failure:
1. Run `SIMPLECOV=1 bundle exec rspec <spec>`.
1. Run `scripts/undercoverage`.
2022-08-13 15:12:31 +05:30
If these commands return `undercover: ✅ No coverage is missing in latest changes` then you can apply `~"pipeline:skip-undercoverage"` to bypass pipeline failures.
2022-07-23 23:45:48 +05:30
## Ruby versions testing
Our test suite runs against Ruby 2 in merge requests and default branch pipelines.
2022-08-13 15:12:31 +05:30
We also run our test suite against Ruby 3 on another 2-hourly scheduled pipelines, as GitLab.com will soon run on Ruby 3.
2022-05-07 20:08:51 +05:30
2021-11-18 22:05:49 +05:30
## PostgreSQL versions testing
Our test suite runs against PG12 as GitLab.com runs on PG12 and
[Omnibus defaults to PG12 for new installs and upgrades](../administration/package_information/postgresql_versions.md).
We do run our test suite against PG11 and PG13 on nightly scheduled pipelines.
We also run our test suite against PG11 upon specific database library changes in MRs and `main` pipelines (with the `rspec db-library-code pg11` job).
### Current versions testing
2022-10-11 01:57:18 +05:30
| Where? | PostgreSQL version | Ruby version |
|------------------------------------------------------------------------------------------------|-------------------------------------------------|--------------|
| Merge requests | 12 (default version), 11 for DB library changes | 2.7 (default version) |
| `master` branch commits | 12 (default version), 11 for DB library changes | 2.7 (default version) |
| `maintenance` scheduled pipelines for the `master` branch (every even-numbered hour) | 12 (default version), 11 for DB library changes | 2.7 (default version) |
| `maintenance` scheduled pipelines for the `ruby3` branch (every odd-numbered hour), see below. | 12 (default version), 11 for DB library changes | 3.0 (coded in the branch) |
| `nightly` scheduled pipelines for the `master` branch | 12 (default version), 11, 13 | 2.7 (default version) |
The pipeline configuration for the scheduled pipeline testing Ruby 3 is
stored in the `ruby3-sync` branch. The pipeline updates the `ruby3` branch
with latest `master`, and then it triggers a regular branch pipeline for
`ruby3`. Any changes in `ruby3` are only for running the pipeline. It should
never be merged back to `master`. Any other Ruby 3 changes should go into
`master` directly, which should be compatible with Ruby 2.7.
2021-11-18 22:05:49 +05:30
2022-11-25 23:54:43 +05:30
Previously, `ruby3-sync` was using a project token stored in `RUBY3_SYNC_TOKEN`
(now backed up in `RUBY3_SYNC_TOKEN_NOT_USED`), however due to various
permissions issues, we ended up using an access token from `gitlab-bot` so now
`RUBY3_SYNC_TOKEN` is actually an access token from `gitlab-bot`.
2021-11-18 22:05:49 +05:30
### Long-term plan
We follow the [PostgreSQL versions shipped with Omnibus GitLab](../administration/package_information/postgresql_versions.md):
| PostgreSQL version | 14.1 (July 2021) | 14.2 (August 2021) | 14.3 (September 2021) | 14.4 (October 2021) | 14.5 (November 2021) | 14.6 (December 2021) |
| -------------------| ---------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- | ---------------------- |
| PG12 | MRs/`2-hour`/`nightly` | MRs/`2-hour`/`nightly` | MRs/`2-hour`/`nightly` | MRs/`2-hour`/`nightly` | MRs/`2-hour`/`nightly` | MRs/`2-hour`/`nightly` |
| PG11 | `nightly` | `nightly` | `nightly` | `nightly` | `nightly` | `nightly` |
| PG13 | `nightly` | `nightly` | `nightly` | `nightly` | `nightly` | `nightly` |
2020-10-24 23:57:45 +05:30
2022-05-07 20:08:51 +05:30
## Redis versions testing
Our test suite runs against Redis 6 as GitLab.com runs on Redis 6 and
[Omnibus defaults to Redis 6 for new installs and upgrades](https://gitlab.com/gitlab-org/omnibus-gitlab/-/blob/master/config/software/redis.rb).
We do run our test suite against Redis 5 on `nightly` scheduled pipelines, specifically when running backward-compatible and forward-compatible PostgreSQL jobs.
### Current versions testing
| Where? | Redis version |
| ------ | ------------------ |
| MRs | 6 |
| `default branch` (non-scheduled pipelines) | 6 |
| `nightly` scheduled pipelines | 5 |
2021-11-18 22:05:49 +05:30
## Pipelines types for merge requests
2020-10-24 23:57:45 +05:30
2022-03-02 08:16:31 +05:30
In general, pipelines for an MR fall into one of the following types (from shorter to longer), depending on the changes made in the MR:
- [Documentation pipeline](#documentation-pipeline): For MRs that touch documentation.
- [Backend pipeline](#backend-pipeline): For MRs that touch backend code.
- [Frontend pipeline](#frontend-pipeline): For MRs that touch frontend code.
- [End-to-end pipeline](#end-to-end-pipeline): For MRs that touch code in the `qa/` folder.
2020-10-24 23:57:45 +05:30
2022-07-23 23:45:48 +05:30
A "pipeline type" is an abstract term that mostly describes the "critical path" (for example, the chain of jobs for which the sum
2022-03-02 08:16:31 +05:30
of individual duration equals the pipeline's duration).
2022-11-25 23:54:43 +05:30
We use these "pipeline types" in [metrics dashboards](https://app.periscopedata.com/app/gitlab/858266/GitLab-Pipeline-Durations) to detect what types and jobs need to be optimized first.
2022-03-02 08:16:31 +05:30
An MR that touches multiple areas would be associated with the longest type applicable. For instance, an MR that touches backend
and frontend would fall into the "Frontend" pipeline type since this type takes longer to finish than the "Backend" pipeline type.
2020-10-24 23:57:45 +05:30
2021-09-30 23:02:18 +05:30
We use the [`rules:`](../ci/yaml/index.md#rules) and [`needs:`](../ci/yaml/index.md#needs) keywords extensively
2020-10-24 23:57:45 +05:30
to determine the jobs that need to be run in a pipeline. Note that an MR that includes multiple types of changes would
2021-09-30 23:02:18 +05:30
have a pipelines that include jobs from multiple types (for example, a combination of docs-only and code-only pipelines).
2020-05-24 23:13:21 +05:30
2022-07-16 23:28:13 +05:30
Following are graphs of the critical paths for each pipeline type. Jobs that aren't part of the critical path are omitted.
2022-03-02 08:16:31 +05:30
### Documentation pipeline
2020-05-24 23:13:21 +05:30
2022-03-02 08:16:31 +05:30
[Reference pipeline](https://gitlab.com/gitlab-org/gitlab/-/pipelines/432049110).
2020-05-24 23:13:21 +05:30
```mermaid
graph LR
2022-03-02 08:16:31 +05:30
classDef criticalPath fill:#f66;
1-3["docs-lint links (5 minutes)"];
class 1-3 criticalPath;
click 1-3 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=8356757&udv=0"
2020-05-24 23:13:21 +05:30
```
2022-03-02 08:16:31 +05:30
### Backend pipeline
2020-05-24 23:13:21 +05:30
2022-03-02 08:16:31 +05:30
[Reference pipeline](https://gitlab.com/gitlab-org/gitlab/-/pipelines/433316063).
2020-05-24 23:13:21 +05:30
```mermaid
graph RL;
classDef criticalPath fill:#f66;
2022-03-02 08:16:31 +05:30
1-3["compile-test-assets (6 minutes)"];
class 1-3 criticalPath;
click 1-3 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=6914317&udv=0"
1-6["setup-test-env (4 minutes)"];
click 1-6 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=6914315&udv=0"
1-14["retrieve-tests-metadata"];
click 1-14 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=8356697&udv=0"
1-15["detect-tests"];
click 1-15 "https://app.periscopedata.com/app/gitlab/652085/EP---Jobs-Durations?widget=10113603&udv=1005715"
2_5-1["rspec & db jobs (24 minutes)"];
class 2_5-1 criticalPath;
click 2_5-1 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations"
2_5-1 --> 1-3 & 1-6 & 1-14 & 1-15;
3_2-1["rspec:coverage (5.35 minutes)"];
class 3_2-1 criticalPath;
click 3_2-1 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=7248745&udv=0"
3_2-1 -.->|"(don't use needs<br/>because of limitations)"| 2_5-1;
4_3-1["rspec:undercoverage (3.5 minutes)"];
class 4_3-1 criticalPath;
click 4_3-1 "https://app.periscopedata.com/app/gitlab/652085/EP---Jobs-Durations?widget=13446492&udv=1005715"
4_3-1 --> 3_2-1;
2020-05-24 23:13:21 +05:30
```
2022-03-02 08:16:31 +05:30
### Frontend pipeline
2020-05-24 23:13:21 +05:30
2022-03-02 08:16:31 +05:30
[Reference pipeline](https://gitlab.com/gitlab-org/gitlab/-/pipelines/431913287).
2020-05-24 23:13:21 +05:30
```mermaid
graph RL;
classDef criticalPath fill:#f66;
2022-03-02 08:16:31 +05:30
1-2["build-qa-image (2 minutes)"];
click 1-2 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=6914325&udv=0"
1-5["compile-production-assets (16 minutes)"];
class 1-5 criticalPath;
click 1-5 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=6914312&udv=0"
2_3-1["build-assets-image (1.3 minutes)"];
2020-05-24 23:13:21 +05:30
class 2_3-1 criticalPath;
2022-03-02 08:16:31 +05:30
2_3-1 --> 1-5
2_6-1["start-review-app-pipeline (49 minutes)"];
class 2_6-1 criticalPath;
click 2_6-1 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations"
2_6-1 --> 2_3-1 & 1-2;
2020-05-24 23:13:21 +05:30
```
2022-03-02 08:16:31 +05:30
### End-to-end pipeline
2020-05-24 23:13:21 +05:30
2022-03-02 08:16:31 +05:30
[Reference pipeline](https://gitlab.com/gitlab-org/gitlab/-/pipelines/431918463).
2019-12-04 20:38:33 +05:30
```mermaid
graph RL;
2020-05-24 23:13:21 +05:30
classDef criticalPath fill:#f66;
2022-03-02 08:16:31 +05:30
1-2["build-qa-image (2 minutes)"];
click 1-2 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=6914325&udv=0"
1-5["compile-production-assets (16 minutes)"];
class 1-5 criticalPath;
click 1-5 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=6914312&udv=0"
1-15["detect-tests"];
click 1-15 "https://app.periscopedata.com/app/gitlab/652085/EP---Jobs-Durations?widget=10113603&udv=1005715"
2_3-1["build-assets-image (1.3 minutes)"];
class 2_3-1 criticalPath;
2_3-1 --> 1-5
2022-10-11 01:57:18 +05:30
2_4-1["e2e:package-and-test (102 minutes)"];
2022-03-02 08:16:31 +05:30
class 2_4-1 criticalPath;
click 2_4-1 "https://app.periscopedata.com/app/gitlab/652085/Engineering-Productivity---Pipeline-Build-Durations?widget=6914305&udv=0"
2_4-1 --> 1-2 & 2_3-1 & 1-15;
2019-12-04 20:38:33 +05:30
```
2021-11-18 22:05:49 +05:30
## CI configuration internals
2021-03-08 18:12:59 +05:30
2021-11-18 22:05:49 +05:30
### Workflow rules
2021-03-08 18:12:59 +05:30
2021-11-18 22:05:49 +05:30
Pipelines for the GitLab project are created using the [`workflow:rules` keyword](../ci/yaml/index.md#workflow)
feature of the GitLab CI/CD.
2020-06-23 00:09:42 +05:30
2021-11-18 22:05:49 +05:30
Pipelines are always created for the following scenarios:
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
- `main` branch, including on schedules, pushes, merges, and so on.
- Merge requests.
- Tags.
- Stable, `auto-deploy`, and security branches.
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
Pipeline creation is also affected by the following CI/CD variables:
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
- If `$FORCE_GITLAB_CI` is set, pipelines are created.
- If `$GITLAB_INTERNAL` is not set, pipelines are not created.
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
No pipeline is created in any other cases (for example, when pushing a branch with no
MR for it).
2021-06-08 01:23:25 +05:30
2021-11-18 22:05:49 +05:30
The source of truth for these workflow rules is defined in [`.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab-ci.yml).
2021-06-08 01:23:25 +05:30
2021-11-18 22:05:49 +05:30
### Default image
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
The default image is defined in [`.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab-ci.yml).
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
<!-- vale gitlab.Spelling = NO -->
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
It includes Ruby, Go, Git, Git LFS, Chrome, Node, Yarn, PostgreSQL, and Graphics Magick.
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
<!-- vale gitlab.Spelling = YES -->
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
The images used in our pipelines are configured in the
[`gitlab-org/gitlab-build-images`](https://gitlab.com/gitlab-org/gitlab-build-images)
project, which is push-mirrored to [`gitlab/gitlab-build-images`](https://dev.gitlab.org/gitlab/gitlab-build-images)
for redundancy.
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
The current version of the build images can be found in the
["Used by GitLab section"](https://gitlab.com/gitlab-org/gitlab-build-images/blob/master/.gitlab-ci.yml).
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
### Default variables
2020-05-24 23:13:21 +05:30
2021-11-18 22:05:49 +05:30
In addition to the [predefined CI/CD variables](../ci/variables/predefined_variables.md),
each pipeline includes default variables defined in
[`.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab-ci.yml).
2020-06-23 00:09:42 +05:30
### Stages
The current stages are:
2021-03-11 19:13:27 +05:30
- `sync`: This stage is used to synchronize changes from [`gitlab-org/gitlab`](https://gitlab.com/gitlab-org/gitlab) to
[`gitlab-org/gitlab-foss`](https://gitlab.com/gitlab-org/gitlab-foss).
2020-06-23 00:09:42 +05:30
- `prepare`: This stage includes jobs that prepare artifacts that are needed by
jobs in subsequent stages.
- `build-images`: This stage includes jobs that prepare Docker images
that are needed by jobs in subsequent stages or downstream pipelines.
- `fixtures`: This stage includes jobs that prepare fixtures needed by frontend tests.
2021-12-11 22:18:48 +05:30
- `lint`: This stage includes linting and static analysis jobs.
- `test`: This stage includes most of the tests, and DB/migration jobs.
2020-06-23 00:09:42 +05:30
- `post-test`: This stage includes jobs that build reports or gather data from
2021-09-30 23:02:18 +05:30
the `test` stage's jobs (for example, coverage, Knapsack metadata, and so on).
2022-07-16 23:28:13 +05:30
- `review`: This stage includes jobs that build the CNG images, deploy them, and
run end-to-end tests against Review Apps (see [Review Apps](testing_guide/review_apps.md) for details).
It also includes Docs Review App jobs.
2020-06-23 00:09:42 +05:30
- `qa`: This stage includes jobs that perform QA tasks against the Review App
2020-11-24 15:15:51 +05:30
that is deployed in stage `review`.
2020-06-23 00:09:42 +05:30
- `post-qa`: This stage includes jobs that build reports or gather data from
2021-09-30 23:02:18 +05:30
the `qa` stage's jobs (for example, Review App performance report).
2020-06-23 00:09:42 +05:30
- `pages`: This stage includes a job that deploys the various reports as
2021-09-30 23:02:18 +05:30
GitLab Pages (for example, [`coverage-ruby`](https://gitlab-org.gitlab.io/gitlab/coverage-ruby/),
2020-10-24 23:57:45 +05:30
and `webpack-report` (found at `https://gitlab-org.gitlab.io/gitlab/webpack-report/`, but there is
[an issue with the deployment](https://gitlab.com/gitlab-org/gitlab/-/issues/233458)).
2021-04-29 21:17:54 +05:30
- `notify`: This stage includes jobs that notify various failures to Slack.
2020-06-23 00:09:42 +05:30
2021-03-11 19:13:27 +05:30
### Dependency Proxy
Some of the jobs are using images from Docker Hub, where we also use
2022-11-25 23:54:43 +05:30
`${GITLAB_DEPENDENCY_PROXY_ADDRESS}` as a prefix to the image path, so that we pull
2021-03-11 19:13:27 +05:30
images from our [Dependency Proxy](../user/packages/dependency_proxy/index.md).
2022-11-25 23:54:43 +05:30
By default, this variable is set from the value of `${GITLAB_DEPENDENCY_PROXY}`.
2021-03-11 19:13:27 +05:30
2021-04-17 20:07:23 +05:30
`${GITLAB_DEPENDENCY_PROXY}` is a group CI/CD variable defined in
2021-03-11 19:13:27 +05:30
[`gitlab-org`](https://gitlab.com/gitlab-org) as
`${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/`. This means when we use an image
defined as:
```yaml
2022-11-25 23:54:43 +05:30
image: ${GITLAB_DEPENDENCY_PROXY_ADDRESS}alpine:edge
2021-03-11 19:13:27 +05:30
```
Projects in the `gitlab-org` group pull from the Dependency Proxy, while
forks that reside on any other personal namespaces or groups fall back to
Docker Hub unless `${GITLAB_DEPENDENCY_PROXY}` is also defined there.
2022-11-25 23:54:43 +05:30
#### Work around for when a pipeline is started by a Project access token user
When a pipeline is started by a Project access token user (e.g. the `release-tools approver bot` user which
automatically updates the Gitaly version used in the main project),
[the Dependency proxy isn't accessible](https://gitlab.com/gitlab-org/gitlab/-/issues/332411#note_1130388163)
and the job fails at the `Preparing the "docker+machine" executor` step.
To work around that, we have a special workflow rule, that overrides the
`${GITLAB_DEPENDENCY_PROXY_ADDRESS}` variable so that Depdendency proxy isn't used in that case:
```yaml
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $GITLAB_USER_LOGIN =~ /project_\d+_bot\d*/'
variables:
GITLAB_DEPENDENCY_PROXY_ADDRESS: ""
```
NOTE:
We don't directly override the `${GITLAB_DEPENDENCY_PROXY}` variable because group-level
variables have higher precedence over `.gitlab-ci.yml` variables.
2020-06-23 00:09:42 +05:30
### Common job definitions
2021-09-30 23:02:18 +05:30
Most of the jobs [extend from a few CI definitions](../ci/yaml/index.md#extends)
2021-09-04 01:27:46 +05:30
defined in [`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml)
2021-09-30 23:02:18 +05:30
that are scoped to a single [configuration keyword](../ci/yaml/index.md#job-keywords).
2020-06-23 00:09:42 +05:30
| Job definitions | Description |
|------------------|-------------|
2021-09-30 23:02:18 +05:30
| `.default-retry` | Allows a job to [retry](../ci/yaml/index.md#retry) upon `unknown_failure`, `api_failure`, `runner_system_failure`, `job_execution_timeout`, or `stuck_or_timeout_failure`. |
| `.default-before_script` | Allows a job to use a default `before_script` definition suitable for Ruby/Rails tasks that may need a database running (for example, tests). |
2021-03-11 19:13:27 +05:30
| `.setup-test-env-cache` | Allows a job to use a default `cache` definition suitable for setting up test environment for subsequent Ruby/Rails tasks. |
2020-06-23 00:09:42 +05:30
| `.rails-cache` | Allows a job to use a default `cache` definition suitable for Ruby/Rails tasks. |
| `.static-analysis-cache` | Allows a job to use a default `cache` definition suitable for static analysis tasks. |
2021-02-22 17:27:13 +05:30
| `.coverage-cache` | Allows a job to use a default `cache` definition suitable for coverage tasks. |
| `.qa-cache` | Allows a job to use a default `cache` definition suitable for QA tasks. |
2020-06-23 00:09:42 +05:30
| `.yarn-cache` | Allows a job to use a default `cache` definition suitable for frontend jobs that do a `yarn install`. |
| `.assets-compile-cache` | Allows a job to use a default `cache` definition suitable for frontend jobs that compile assets. |
2021-09-04 01:27:46 +05:30
| `.use-pg11` | Allows a job to run the `postgres` 11 and `redis` services (see [`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml) for the specific versions of the services). |
| `.use-pg11-ee` | Same as `.use-pg11` but also use an `elasticsearch` service (see [`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml) for the specific version of the service). |
| `.use-pg12` | Allows a job to use the `postgres` 12 and `redis` services (see [`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml) for the specific versions of the services). |
| `.use-pg12-ee` | Same as `.use-pg12` but also use an `elasticsearch` service (see [`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml) for the specific version of the service). |
2022-05-07 20:08:51 +05:30
| `.use-pg13` | Allows a job to use the `postgres` 13 and `redis` services (see [`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml) for the specific versions of the services). |
| `.use-pg13-ee` | Same as `.use-pg13` but also use an `elasticsearch` service (see [`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml) for the specific version of the service). |
2020-06-23 00:09:42 +05:30
| `.use-kaniko` | Allows a job to use the `kaniko` tool to build Docker images. |
2021-04-17 20:07:23 +05:30
| `.as-if-foss` | Simulate the FOSS project by setting the `FOSS_ONLY='1'` CI/CD variable. |
2021-02-22 17:27:13 +05:30
| `.use-docker-in-docker` | Allows a job to use Docker in Docker. |
2020-06-23 00:09:42 +05:30
### `rules`, `if:` conditions and `changes:` patterns
2021-09-30 23:02:18 +05:30
We're using the [`rules` keyword](../ci/yaml/index.md#rules) extensively.
2020-06-23 00:09:42 +05:30
All `rules` definitions are defined in
2021-03-11 19:13:27 +05:30
[`rules.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/rules.gitlab-ci.yml),
2021-09-30 23:02:18 +05:30
then included in individual jobs via [`extends`](../ci/yaml/index.md#extends).
2020-06-23 00:09:42 +05:30
The `rules` definitions are composed of `if:` conditions and `changes:` patterns,
which are also defined in
[`rules.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/rules.gitlab-ci.yml)
2021-12-11 22:18:48 +05:30
and included in `rules` definitions via [YAML anchors](../ci/yaml/yaml_optimization.md#anchors)
2020-06-23 00:09:42 +05:30
#### `if:` conditions
2021-02-22 17:27:13 +05:30
<!-- vale gitlab.Substitutions = NO -->
2020-06-23 00:09:42 +05:30
| `if:` conditions | Description | Notes |
|------------------|-------------|-------|
2021-02-22 17:27:13 +05:30
| `if-not-canonical-namespace` | Matches if the project isn't in the canonical (`gitlab-org/`) or security (`gitlab-org/security`) namespace. | Use to create a job for forks (by using `when: on_success|manual`), or **not** create a job for forks (by using `when: never`). |
2021-09-30 23:02:18 +05:30
| `if-not-ee` | Matches if the project isn't EE (that is, project name isn't `gitlab` or `gitlab-ee`). | Use to create a job only in the FOSS project (by using `when: on_success|manual`), or **not** create a job if the project is EE (by using `when: never`). |
| `if-not-foss` | Matches if the project isn't FOSS (that is, project name isn't `gitlab-foss`, `gitlab-ce`, or `gitlabhq`). | Use to create a job only in the EE project (by using `when: on_success|manual`), or **not** create a job if the project is FOSS (by using `when: never`). |
2021-04-17 20:07:23 +05:30
| `if-default-refs` | Matches if the pipeline is for `master`, `main`, `/^[\d-]+-stable(-ee)?$/` (stable branches), `/^\d+-\d+-auto-deploy-\d+$/` (auto-deploy branches), `/^security\//` (security branches), merge requests, and tags. | Note that jobs aren't created for branches with this default configuration. |
| `if-master-refs` | Matches if the current branch is `master` or `main`. | |
| `if-master-push` | Matches if the current branch is `master` or `main` and pipeline source is `push`. | |
2022-08-13 15:12:31 +05:30
| `if-master-schedule-maintenance` | Matches if the current branch is `master` or `main` and pipeline runs on a 2-hourly schedule. | |
2021-04-17 20:07:23 +05:30
| `if-master-schedule-nightly` | Matches if the current branch is `master` or `main` and pipeline runs on a nightly schedule. | |
2021-02-22 17:27:13 +05:30
| `if-auto-deploy-branches` | Matches if the current branch is an auto-deploy one. | |
2021-04-17 20:07:23 +05:30
| `if-master-or-tag` | Matches if the pipeline is for the `master` or `main` branch or for a tag. | |
2020-06-23 00:09:42 +05:30
| `if-merge-request` | Matches if the pipeline is for a merge request. | |
2021-10-27 15:23:28 +05:30
| `if-merge-request-title-as-if-foss` | Matches if the pipeline is for a merge request and the MR has label ~"pipeline:run-as-if-foss" | |
| `if-merge-request-title-update-caches` | Matches if the pipeline is for a merge request and the MR has label ~"pipeline:update-cache". | |
| `if-merge-request-title-run-all-rspec` | Matches if the pipeline is for a merge request and the MR has label ~"pipeline:run-all-rspec". | |
2021-02-22 17:27:13 +05:30
| `if-security-merge-request` | Matches if the pipeline is for a security merge request. | |
| `if-security-schedule` | Matches if the pipeline is for a security scheduled pipeline. | |
2020-06-23 00:09:42 +05:30
| `if-nightly-master-schedule` | Matches if the pipeline is for a `master` scheduled pipeline with `$NIGHTLY` set. | |
| `if-dot-com-gitlab-org-schedule` | Limits jobs creation to scheduled pipelines for the `gitlab-org` group on GitLab.com. | |
2021-04-17 20:07:23 +05:30
| `if-dot-com-gitlab-org-master` | Limits jobs creation to the `master` or `main` branch for the `gitlab-org` group on GitLab.com. | |
2020-06-23 00:09:42 +05:30
| `if-dot-com-gitlab-org-merge-request` | Limits jobs creation to merge requests for the `gitlab-org` group on GitLab.com. | |
| `if-dot-com-gitlab-org-and-security-tag` | Limits job creation to tags for the `gitlab-org` and `gitlab-org/security` groups on GitLab.com. | |
| `if-dot-com-gitlab-org-and-security-merge-request` | Limit jobs creation to merge requests for the `gitlab-org` and `gitlab-org/security` groups on GitLab.com. | |
2021-02-22 17:27:13 +05:30
| `if-dot-com-gitlab-org-and-security-tag` | Limit jobs creation to tags for the `gitlab-org` and `gitlab-org/security` groups on GitLab.com. | |
2020-06-23 00:09:42 +05:30
| `if-dot-com-ee-schedule` | Limits jobs to scheduled pipelines for the `gitlab-org/gitlab` project on GitLab.com. | |
2021-02-22 17:27:13 +05:30
| `if-security-pipeline-merge-result` | Matches if the pipeline is for a security merge request triggered by `@gitlab-release-tools-bot`. | |
<!-- vale gitlab.Substitutions = YES -->
2020-06-23 00:09:42 +05:30
#### `changes:` patterns
| `changes:` patterns | Description |
|------------------------------|--------------------------------------------------------------------------|
2021-02-22 17:27:13 +05:30
| `ci-patterns` | Only create job for CI configuration-related changes. |
| `ci-build-images-patterns` | Only create job for CI configuration-related changes related to the `build-images` stage. |
| `ci-review-patterns` | Only create job for CI configuration-related changes related to the `review` stage. |
| `ci-qa-patterns` | Only create job for CI configuration-related changes related to the `qa` stage. |
| `yaml-lint-patterns` | Only create job for YAML-related changes. |
2020-06-23 00:09:42 +05:30
| `docs-patterns` | Only create job for docs-related changes. |
2021-09-30 23:02:18 +05:30
| `frontend-dependency-patterns` | Only create job when frontend dependencies are updated (that is, `package.json`, and `yarn.lock`). changes. |
2020-06-23 00:09:42 +05:30
| `frontend-patterns` | Only create job for frontend-related changes. |
2021-02-22 17:27:13 +05:30
| `backend-patterns` | Only create job for backend-related changes. |
| `db-patterns` | Only create job for DB-related changes. |
2021-09-30 23:02:18 +05:30
| `backstage-patterns` | Only create job for backstage-related changes (that is, Danger, fixtures, RuboCop, specs). |
2020-06-23 00:09:42 +05:30
| `code-patterns` | Only create job for code-related changes. |
| `qa-patterns` | Only create job for QA-related changes. |
| `code-backstage-patterns` | Combination of `code-patterns` and `backstage-patterns`. |
| `code-qa-patterns` | Combination of `code-patterns` and `qa-patterns`. |
| `code-backstage-qa-patterns` | Combination of `code-patterns`, `backstage-patterns`, and `qa-patterns`. |
2022-08-13 15:12:31 +05:30
| `static-analysis-patterns` | Only create jobs for Static Analytics configuration-related changes. |
2020-06-23 00:09:42 +05:30
2021-11-18 22:05:49 +05:30
## Performance
### Interruptible pipelines
By default, all jobs are [interruptible](../ci/yaml/index.md#interruptible), except the
`dont-interrupt-me` job which runs automatically on `main`, and is `manual`
otherwise.
If you want a running pipeline to finish even if you push new commits to a merge
request, be sure to start the `dont-interrupt-me` job before pushing.
2022-05-07 20:08:51 +05:30
### Git fetch caching
Because GitLab.com uses the [pack-objects cache](../administration/gitaly/configure_gitaly.md#pack-objects-cache),
concurrent Git fetches of the same pipeline ref are deduplicated on
the Gitaly server (always) and served from cache (when available).
This works well for the following reasons:
- The pack-objects cache is enabled on all Gitaly servers on GitLab.com.
- The CI/CD [Git strategy setting](../ci/pipelines/settings.md#choose-the-default-git-strategy) for `gitlab-org/gitlab` is **Git clone**,
causing all jobs to fetch the same data, which maximizes the cache hit ratio.
- We use [shallow clone](../ci/pipelines/settings.md#limit-the-number-of-changes-fetched-during-clone) to avoid downloading the full Git
history for every job.
2021-11-18 22:05:49 +05:30
### Caching strategy
1. All jobs must only pull caches by default.
1. All jobs must be able to pass with an empty cache. In other words, caches are only there to speed up jobs.
1. We currently have several different cache definitions defined in
[`.gitlab/ci/global.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/global.gitlab-ci.yml),
with fixed keys:
- `.setup-test-env-cache`
2021-12-11 22:18:48 +05:30
- `.ruby-cache`
2021-11-18 22:05:49 +05:30
- `.rails-cache`
- `.static-analysis-cache`
2021-12-11 22:18:48 +05:30
- `.rubocop-cache`
2021-11-18 22:05:49 +05:30
- `.coverage-cache`
2022-11-25 23:54:43 +05:30
- `.ruby-node-cache`
2021-11-18 22:05:49 +05:30
- `.qa-cache`
- `.yarn-cache`
- `.assets-compile-cache` (the key includes `${NODE_ENV}` so it's actually two different caches).
1. These cache definitions are composed of [multiple atomic caches](../ci/caching/index.md#use-multiple-caches).
2022-08-13 15:12:31 +05:30
1. Only the following jobs, running in 2-hourly `maintenance` scheduled pipelines, are pushing (that is, updating) to the caches:
2021-11-18 22:05:49 +05:30
- `update-setup-test-env-cache`, defined in [`.gitlab/ci/rails.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/rails.gitlab-ci.yml).
- `update-gitaly-binaries-cache`, defined in [`.gitlab/ci/rails.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/rails.gitlab-ci.yml).
2021-12-11 22:18:48 +05:30
- `update-rubocop-cache`, defined in [`.gitlab/ci/rails.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/rails.gitlab-ci.yml).
2021-11-18 22:05:49 +05:30
- `update-qa-cache`, defined in [`.gitlab/ci/qa.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/qa.gitlab-ci.yml).
- `update-assets-compile-production-cache`, defined in [`.gitlab/ci/frontend.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/frontend.gitlab-ci.yml).
- `update-assets-compile-test-cache`, defined in [`.gitlab/ci/frontend.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/frontend.gitlab-ci.yml).
- `update-yarn-cache`, defined in [`.gitlab/ci/frontend.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/frontend.gitlab-ci.yml).
- `update-storybook-yarn-cache`, defined in [`.gitlab/ci/frontend.gitlab-ci.yml`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/.gitlab/ci/frontend.gitlab-ci.yml).
1. These jobs can also be forced to run in merge requests with the `pipeline:update-cache` label (this can be useful to warm the caches in a MR that updates the cache keys).
### Artifacts strategy
2022-11-25 23:54:43 +05:30
We limit the artifacts that are saved and retrieved by jobs to the minimum to reduce the upload/download time and costs, as well as the artifacts storage.
2021-11-18 22:05:49 +05:30
2022-05-07 20:08:51 +05:30
### Components caching
2021-11-18 22:05:49 +05:30
2022-11-25 23:54:43 +05:30
Some external components (GitLab Workhorse and frontend assets) of GitLab need to be built from source as a preliminary step for running tests.
#### `cache-workhorse`
2021-11-18 22:05:49 +05:30
2022-11-25 23:54:43 +05:30
In [this MR](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/79766), and then
[this MR](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/96297),
we introduced a new `cache-workhorse` job that:
2021-11-18 22:05:49 +05:30
2022-05-07 20:08:51 +05:30
- runs automatically for all GitLab.com `gitlab-org/gitlab` scheduled pipelines
- runs automatically for any `master` commit that touches the `workhorse/` folder
2022-11-25 23:54:43 +05:30
- is manual for GitLab.com's `gitlab-org`'s MRs that touches caching-related files
2022-05-07 20:08:51 +05:30
This job tries to download a generic package that contains GitLab Workhorse binaries needed in the GitLab test suite (under `tmp/tests/gitlab-workhorse`).
- If the package URL returns a 404:
1. It runs `scripts/setup-test-env`, so that the GitLab Workhorse binaries are built.
1. It then creates an archive which contains the binaries and upload it [as a generic package](https://gitlab.com/gitlab-org/gitlab/-/packages/).
2022-11-25 23:54:43 +05:30
- Otherwise, if the package already exists, it exits the job successfully.
2022-05-07 20:08:51 +05:30
We also changed the `setup-test-env` job to:
2022-11-25 23:54:43 +05:30
1. First download the GitLab Workhorse generic package build and uploaded by `cache-workhorse`.
2022-07-23 23:45:48 +05:30
1. If the package is retrieved successfully, its content is placed in the right folder (for example, `tmp/tests/gitlab-workhorse`), preventing the building of the binaries when `scripts/setup-test-env` is run later on.
2022-05-07 20:08:51 +05:30
1. If the package URL returns a 404, the behavior doesn't change compared to the current one: the GitLab Workhorse binaries are built as part of `scripts/setup-test-env`.
NOTE:
2022-07-23 23:45:48 +05:30
The version of the package is the workhorse tree SHA (for example, `git rev-parse HEAD:workhorse`).
2021-11-18 22:05:49 +05:30
2022-11-25 23:54:43 +05:30
#### `cache-assets`
In [this MR](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/96297),
we introduced three new `cache-assets:test`, `cache-assets:test as-if-foss`,
and `cache-assets:production` jobs that:
- never run unless `$CACHE_ASSETS_AS_PACKAGE == "true"`
- runs automatically for all GitLab.com `gitlab-org/gitlab` scheduled pipelines
- runs automatically for any `master` commit that touches the assets-related folders
- is manual for GitLab.com's `gitlab-org`'s MRs that touches caching-related files
This job tries to download a generic package that contains GitLab compiled assets
needed in the GitLab test suite (under `app/assets/javascripts/locale/**/app.js`,
and `public/assets`).
- If the package URL returns a 404:
1. It runs `bin/rake gitlab:assets:compile`, so that the GitLab assets are compiled.
1. It then creates an archive which contains the assets and uploads it [as a generic package](https://gitlab.com/gitlab-org/gitlab/-/packages/).
The package version is set to the assets folders' hash sum.
- Otherwise, if the package already exists, it exits the job successfully.
#### `compile-*-assets`
We also changed the `compile-test-assets`, `compile-test-assets as-if-foss`,
and `compile-production-assets` jobs to:
1. First download the "native" cache assets, which contain:
- The [compiled assets](https://gitlab.com/gitlab-org/gitlab/-/blob/a6910c9086bb28e553f5e747ec2dd50af6da3c6b/.gitlab/ci/global.gitlab-ci.yml#L86-87).
- A [`cached-assets-hash.txt` file](https://gitlab.com/gitlab-org/gitlab/-/blob/a6910c9086bb28e553f5e747ec2dd50af6da3c6b/.gitlab/ci/global.gitlab-ci.yml#L85)
containing the `SHA256` hexdigest of all the source files on which the assets depend on.
This list of files is a pessimistic list and the assets might not depend on
some of these files. At worst we compile the assets more often, which is better than
using outdated assets.
The file is [created after assets are compiled](https://gitlab.com/gitlab-org/gitlab/-/blob/a6910c9086bb28e553f5e747ec2dd50af6da3c6b/.gitlab/ci/frontend.gitlab-ci.yml#L83).
1. We then we compute the `SHA256` hexdigest of all the source files the assets depend on, **for the current checked out branch**. We [store the hexdigest in the `GITLAB_ASSETS_HASH` variable](https://gitlab.com/gitlab-org/gitlab/-/blob/a6910c9086bb28e553f5e747ec2dd50af6da3c6b/.gitlab/ci/frontend.gitlab-ci.yml#L27).
1. If `$CACHE_ASSETS_AS_PACKAGE == "true"`, we download the generic package built and uploaded by [`cache-assets:*`](#cache-assets).
- If the cache is up-to-date for the checked out branch, we download the native cache
**and** the cache package. We could optimize that by not downloading
the genetic package but the native cache is actually very often outdated because it's
rebuilt only every 2 hours.
1. We [run the `assets_compile_script` function](https://gitlab.com/gitlab-org/gitlab/-/blob/a6910c9086bb28e553f5e747ec2dd50af6da3c6b/.gitlab/ci/frontend.gitlab-ci.yml#L35),
which [itself runs](https://gitlab.com/gitlab-org/gitlab/-/blob/c023191ef412e868ae957f3341208a41ca678403/scripts/utils.sh#L76)
the [`assets:compile` Rake task](https://gitlab.com/gitlab-org/gitlab/-/blob/c023191ef412e868ae957f3341208a41ca678403/lib/tasks/gitlab/assets.rake#L80-109).
This task is responsible for deciding if assets need to be compiled or not.
It [compares the `HEAD` `SHA256` hexdigest from `$GITLAB_ASSETS_HASH` with the `master` hexdigest from `cached-assets-hash.txt`](https://gitlab.com/gitlab-org/gitlab/-/blob/c023191ef412e868ae957f3341208a41ca678403/lib/tasks/gitlab/assets.rake#L86).
1. If the hashes are the same, we don't compile anything. If they're different, we compile the assets.
2021-12-11 22:18:48 +05:30
### Pre-clone step
2021-11-18 22:05:49 +05:30
2021-12-11 22:18:48 +05:30
NOTE:
We no longer use this optimization for `gitlab-org/gitlab` because the [pack-objects cache](../administration/gitaly/configure_gitaly.md#pack-objects-cache)
allows Gitaly to serve the full CI/CD fetch traffic now. See [Git fetch caching](#git-fetch-caching).
2021-11-18 22:05:49 +05:30
2021-12-11 22:18:48 +05:30
The pre-clone step works by using the `CI_PRE_CLONE_SCRIPT` variable
2022-01-26 12:08:38 +05:30
[defined by GitLab.com shared runners](../ci/runners/saas/linux_saas_runner.md#pre-clone-script).
2021-11-18 22:05:49 +05:30
2019-12-04 20:38:33 +05:30
---
2021-09-30 23:02:18 +05:30
[Return to Development documentation](index.md)