Skip to content
Snippets Groups Projects
Commit d8fe7cec authored by Marcel Amirault's avatar Marcel Amirault
Browse files

Clarify details about duplicate pipeline avoidance

parent ca1e35f7
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -213,7 +213,7 @@ The variable names begin with the `CI_MERGE_REQUEST_` prefix.
### Two pipelines created when pushing to a merge request
 
If you are experiencing duplicated pipelines when using `rules`, take a look at
the [important differences between `rules` and `only`/`except`](../yaml/README.md#prevent-duplicate-pipelines),
the [important differences between `rules` and `only`/`except`](../yaml/README.md#avoid-duplicate-pipelines),
which helps you get your starting configuration correct.
 
If you are seeing two pipelines when using `only/except`, please see the caveats
Loading
Loading
Loading
Loading
@@ -119,7 +119,7 @@ associated with it. Usually one pipeline is a merge request pipeline, and the ot
is a branch pipeline.
 
This is usually caused by the `rules` configuration, and there are several ways to
[prevent duplicate pipelines](yaml/README.md#prevent-duplicate-pipelines).
[prevent duplicate pipelines](yaml/README.md#avoid-duplicate-pipelines).
 
#### A job is not in the pipeline
 
Loading
Loading
@@ -258,7 +258,7 @@ When you use [`rules`](yaml/README.md#rules) with a `when:` clause without an `i
clause, multiple pipelines may run. Usually this occurs when you push a commit to
a branch that has an open merge request associated with it.
 
To [prevent duplicate pipelines](yaml/README.md#prevent-duplicate-pipelines), use
To [prevent duplicate pipelines](yaml/README.md#avoid-duplicate-pipelines), use
[`workflow: rules`](yaml/README.md#workflowrules) or rewrite your rules to control
which pipelines can run.
 
Loading
Loading
Loading
Loading
@@ -300,7 +300,7 @@ The final `when: always` rule runs all other pipeline types, **including** merge
request pipelines.
 
If your rules match both branch pipelines and merge request pipelines,
[duplicate pipelines](#prevent-duplicate-pipelines) can occur.
[duplicate pipelines](#avoid-duplicate-pipelines) can occur.
 
#### `workflow:rules` templates
 
Loading
Loading
@@ -339,7 +339,7 @@ include:
- template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
```
 
#### Run both branch and merge request pipelines without duplication
#### Use both branch and merge request pipelines without duplication
 
> [Introduced in](https://gitlab.com/gitlab-org/gitlab/-/issues/201845) GitLab 13.8.
 
Loading
Loading
@@ -350,14 +350,8 @@ a merge request is created. Use this variable to:
- Run jobs in branch pipelines when there is no merge request open for the branch.
- Run jobs in merge request pipelines when there is a merge request open for the branch.
 
This example runs branch and merge request pipelines only, but does not run
pipelines for any other case. The configuration can be translated as:
- If the pipeline is triggered by a merge request, run a merge request pipeline.
- If the pipeline is triggered by a change to a branch, but a merge request is open
for that branch, do not run a branch pipeline.
- If the pipeline is triggered by a change to a branch, but without any open merge requests,
run a branch pipeline.
This example is for a project that runs branch and merge request pipelines only,
but does not run pipelines for any other case:
 
```yaml
workflow:
Loading
Loading
@@ -368,8 +362,16 @@ workflow:
- if: '$CI_COMMIT_BRANCH'
```
 
- If the pipeline is triggered by a merge request, run a merge request pipeline.
For example, a merge request pipeline can be triggered by a push to a branch with
an associated open merge request.
- If the pipeline is triggered by a change to a branch, but a merge request is open
for that branch, do not run a branch pipeline.
- If the pipeline is triggered by a change to a branch, but without any open merge requests,
run a branch pipeline.
Alternatively, you can add a rule to an existing `workflow` section that prevents
[duplicated pipelines](#prevent-duplicate-pipelines). Add this rule at the top of
[duplicated pipelines](#avoid-duplicate-pipelines). Add this rule at the top of
the `workflow` section, followed by the other rules that were already there:
 
```yaml
Loading
Loading
@@ -381,8 +383,8 @@ workflow:
```
 
Some [pipelines triggered by the API](../triggers/README.md) also have a `$CI_COMMIT_BRANCH`
set. The `$CI_PIPELINE_SOURCE == "push"` is needed to make sure those triggered pipelines
are not blocked by the rule.
set. The `$CI_PIPELINE_SOURCE == "push"` makes sure those triggered pipelines are
not blocked by the rule.
 
### `include`
 
Loading
Loading
@@ -1145,17 +1147,15 @@ WARNING:
If you use a `when:` clause as the final rule (not including `when: never`), two
simultaneous pipelines may start. Both push pipelines and merge request pipelines can
be triggered by the same event (a push to the source branch for an open merge request).
See how to [prevent duplicate pipelines](#prevent-duplicate-pipelines)
See how to [prevent duplicate pipelines](#avoid-duplicate-pipelines)
for more details.
 
#### Prevent duplicate pipelines
Jobs defined with `rules` can trigger multiple pipelines with the same action. You
don't have to explicitly configure rules for each type of pipeline to trigger them
accidentally. Rules that are too broad could cause simultaneous pipelines of a different
type to run unexpectedly.
#### Avoid duplicate pipelines
 
You can prevent duplicate pipelines with [`workflow` rules](#run-both-branch-and-merge-request-pipelines-without-duplication).
A single action, like pushing a commit to a branch, can trigger multiple pipelines when
using `rules` in jobs. You don't have to explicitly configure rules for each type
of pipeline to trigger them accidentally. Rules that are too broad could cause simultaneous
pipelines of a different type to run unexpectedly.
 
Some configurations that have the potential to cause duplicate pipelines cause a
[pipeline warning](../troubleshooting.md#pipeline-warnings) to be displayed.
Loading
Loading
@@ -1180,9 +1180,7 @@ causes duplicated pipelines.
There are multiple ways to avoid duplicate pipelines:
 
- Use [`workflow: rules`](#workflowrules) to specify which types of pipelines
can run. To eliminate duplicate pipelines, use merge request pipelines only
or push (branch) pipelines only.
can run.
- Rewrite the rules to run the job only in very specific cases,
and avoid a final `when:` rule:
 
Loading
Loading
@@ -1193,7 +1191,7 @@ There are multiple ways to avoid duplicate pipelines:
- if: '$CUSTOM_VARIABLE == "true" && $CI_PIPELINE_SOURCE == "merge_request_event"'
```
 
You can prevent duplicate pipelines by changing the job rules to avoid either push (branch)
You can also avoid duplicate pipelines by changing the job rules to avoid either push (branch)
pipelines or merge request pipelines. However, if you use a `- when: always` rule without
`workflow: rules`, GitLab still displays a [pipeline warning](../troubleshooting.md#pipeline-warnings).
 
Loading
Loading
@@ -1209,7 +1207,8 @@ job:
- when: always
```
 
Do not include both push and merge request pipelines in the same job:
You should not include both push and merge request pipelines in the same job without
[`workflow:rules` that prevent duplicate pipelines](#run-both-branch-and-merge-request-pipelines-without-duplication):
 
```yaml
job:
Loading
Loading
@@ -1239,14 +1238,6 @@ runs the other job (`job-with-rules`). Jobs with no rules default
to [`except: merge_requests`](#onlyexcept-basic), so `job-with-no-rules`
runs in all cases except merge requests.
 
It is not possible to define rules based on whether or not a branch has an open
merge request associated with it. You can't configure a job to be included in:
- Only branch pipelines when the branch doesn't have a merge request associated with it.
- Only merge request pipelines when the branch has a merge request associated with it.
See the [related issue](https://gitlab.com/gitlab-org/gitlab/-/issues/201845) for more details.
#### `rules:if`
 
`rules:if` clauses determine whether or not jobs are added to a pipeline by evaluating
Loading
Loading
Loading
Loading
@@ -94,7 +94,7 @@ merge-request-pipeline-job:
```
 
You should avoid configuration like this, and only use branch (`push`) pipelines
or merge request pipelines, when possible. See [`rules` documentation](../../../ci/yaml/README.md#prevent-duplicate-pipelines)
or merge request pipelines, when possible. See [`rules` documentation](../../../ci/yaml/README.md#avoid-duplicate-pipelines)
for details on avoiding two pipelines for a single merge request.
 
### Skipped pipelines
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment