2019-08-15 22:00:36 -04:00
---
2020-05-29 14:08:26 -04:00
stage: Verify
2021-05-26 23:10:55 -04:00
group: Pipeline Authoring
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2019-08-15 22:00:36 -04:00
type: reference
---
2021-09-07 20:11:00 -04:00
# Directed Acyclic Graph **(FREE)**
2019-08-15 22:00:36 -04:00
2020-05-20 23:08:00 -04:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/47063) in GitLab 12.2.
2020-04-21 11:21:10 -04:00
> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/issues/206902) in GitLab 12.10.
2019-08-15 22:00:36 -04:00
A [directed acyclic graph ](https://www.techopedia.com/definition/5739/directed-acyclic-graph-dag ) can be
used in the context of a CI/CD pipeline to build relationships between jobs such that
execution is performed in the quickest possible manner, regardless how stages may
be set up.
For example, you may have a specific tool or separate website that is built
as part of your main project. Using a DAG, you can specify the relationship between
2020-11-18 10:09:08 -05:00
these jobs and GitLab executes the jobs as soon as possible instead of waiting
2019-08-15 22:00:36 -04:00
for each stage to complete.
Unlike other DAG solutions for CI/CD, GitLab does not require you to choose one or the
other. You can implement a hybrid combination of DAG and traditional
stage-based operation within a single pipeline. Configuration is kept very simple,
requiring a single keyword to enable the feature for any job.
Consider a monorepo as follows:
2020-02-05 04:08:43 -05:00
```plaintext
2019-08-15 22:00:36 -04:00
./service_a
./service_b
./service_c
./service_d
```
It has a pipeline that looks like the following:
| build | test | deploy |
| ----- | ---- | ------ |
| build_a | test_a | deploy_a |
| build_b | test_b | deploy_b |
2019-08-28 02:06:34 -04:00
| build_c | test_c | deploy_c |
2019-08-15 22:00:36 -04:00
| build_d | test_d | deploy_d |
Using a DAG, you can relate the `_a` jobs to each other separately from the `_b` jobs,
2020-11-18 10:09:08 -05:00
and even if service `a` takes a very long time to build, service `b` doesn't
wait for it and finishes as quickly as it can. In this very same pipeline, `_c` and
`_d` can be left alone and run together in staged sequence just like any normal
2019-08-15 22:00:36 -04:00
GitLab pipeline.
## Use cases
A DAG can help solve several different kinds of relationships between jobs within
a CI/CD pipeline. Most typically this would cover when jobs need to fan in or out,
and/or merge back together (diamond dependencies). This can happen when you're
handling multi-platform builds or complex webs of dependencies as in something like
an operating system build or a complex deployment graph of independently deployable
but related microservices.
Additionally, a DAG can help with general speediness of pipelines and helping
to deliver fast feedback. By creating dependency relationships that don't unnecessarily
2020-11-18 10:09:08 -05:00
block each other, your pipelines run as quickly as possible regardless of
2019-08-15 22:00:36 -04:00
pipeline stages, ensuring output (including errors) is available to developers
as quickly as possible.
## Usage
2021-12-01 04:10:25 -05:00
Relationships are defined between jobs using the [`needs` keyword ](../yaml/index.md#needs ).
2019-08-15 22:00:36 -04:00
2021-12-01 04:10:25 -05:00
Note that `needs` also works with the [parallel ](../yaml/index.md#parallel ) keyword,
2019-08-20 12:54:52 -04:00
giving you powerful options for parallelization within your pipeline.
2019-08-15 22:00:36 -04:00
## Limitations
A directed acyclic graph is a complicated feature, and as of the initial MVC there
2021-11-17 13:14:12 -05:00
are certain use cases that you may need to work around. For more information, check the:
2019-08-15 22:00:36 -04:00
2021-11-17 13:14:12 -05:00
- [`needs` additional details ](../yaml/index.md#needs ).
2019-09-29 20:06:04 -04:00
- Related epic [tracking planned improvements ](https://gitlab.com/groups/gitlab-org/-/epics/1716 ).
2020-06-09 11:08:05 -04:00
2020-11-16 13:09:15 -05:00
## Needs Visualization
2020-06-09 11:08:05 -04:00
2022-02-28 07:15:45 -05:00
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/215517) in GitLab 13.1 as a [Beta feature](../../policy/alpha-beta-support.md#beta-features).
2020-08-05 11:09:59 -04:00
> - It became a [standard feature](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/38517) in 13.3.
2021-01-22 16:09:10 -05:00
> - [Feature flag removed](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/52208) in GitLab 13.9.
2020-06-09 11:08:05 -04:00
2020-11-18 10:09:08 -05:00
The needs visualization makes it easier to visualize the relationships between dependent jobs in a DAG. This graph displays all the jobs in a pipeline that need or are needed by other jobs. Jobs with no relationships are not displayed in this view.
2020-06-09 11:08:05 -04:00
2021-12-01 04:10:25 -05:00
To see the needs visualization, click on the **Needs** tab when viewing a pipeline that uses the `needs` keyword.
2020-11-16 13:09:15 -05:00
![Needs visualization example ](img/dag_graph_example_v13_1.png )
2020-06-09 11:08:05 -04:00
2020-11-18 10:09:08 -05:00
Clicking a node highlights all the job paths it depends on.
2020-06-09 11:08:05 -04:00
2020-11-16 13:09:15 -05:00
![Needs visualization with path highlight ](img/dag_graph_example_clicked_v13_1.png )
2021-04-26 11:10:20 -04:00
You can also see `needs` relationships in [full pipeline graphs ](../pipelines/index.md#view-full-pipeline-graph ).