Understanding How Rule Scopes Work in Quality Gates

Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Overview

Quality Gates allows you to gate your workflows based on signals in Datadog. When creating a rule, you can define a rule scope, which states when the rule should be evaluated.

To filter rules that are evaluated for a specific CI pipeline, you can add a custom scope when creating a rule. This process requires you to use the --scope option with the datadog-ci gate evaluate command in your build configuration.

For example:

datadog-ci gate evaluate --scope team:backend --scope team:frontend

Define a rule scope

When the datadog-ci gate evaluate command is invoked, the rules having a scope matching the command context are evaluated, and you can filter on rules that tag the backend or frontend teams.

Rule scope for rules always evaluated

For each scope (for example, branch), you can select included or excluded values.

  • When included values are selected, the rule is evaluated if one or more included values are part of the command context.
  • When excluded values are selected, the rule is not evaluated if any of the excluded values are part of the command context.

To create a rule that is evaluated in all branches except main of the example-repository repository, you can create a rule with the following scope.

  1. Click Select when to evaluate.
  2. Enter example-repository in the Repository field and click Include.
  3. Click Add Filter and select Branch.
  4. Enter main in the Branch field and click Exclude.
Rule scope for example-repository and not main branch

If a rule does not contain a scope, it is evaluated for all values for that scope. For example, if a rule does not contain the repository scope, it is evaluated for all repositories.

Add a custom scope

In addition to branch and repository, you can define custom scopes to filter rules that are evaluated for a specific CI pipeline.

Adding a custom scope to a rule scope in Quality Gates

To add a custom scope when creating a rule:

  1. Click + Add Filter and select Custom Scope.
  2. Define the scope name, for example, team.
  3. Define the scope’s included or excluded values.

Unlike the branch and repository scopes, custom scopes must be passed to the datadog-ci gate evaluate command using the --scope option.

For example, you can create a rule that is evaluated for the example-repository repository, but only when the team is backend.

  1. Click Select when to evaluate.

  2. Enter example-repository in the Repository field and click Include.

  3. Click Add Filter and select Custom scope.

  4. Enter a tag name and click Add Custom Scope.

    Rule scope for example-repository and team backend
  5. Enter backend in the team field and click Include.

Rule scope for example-repository and team backend

The rule is evaluated when the following command is invoked in a CI pipeline of the example-repository repository:

  • datadog-ci gate evaluate --scope team:backend

The rule is not evaluated when the following commands are invoked instead:

  • datadog-ci gate evaluate, which does not specify any team.
  • datadog-ci gate evaluate --scope team:api --scope team:frontend, which specifies teams other than backend.

Further reading

Documentation, liens et articles supplémentaires utiles:

PREVIEWING: mervebolat/span-id-preprocessing