Understanding How Rule Scopes Work in Quality Gates
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください。
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.
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.
- Click
Select when to evaluate
. - Enter
example-repository
in the Repository field and click Include. - Click Add Filter and select Branch.
- Enter
main
in the Branch field and click Exclude.
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.
To add a custom scope when creating a rule:
- Click + Add Filter and select Custom Scope.
- Define the scope name, for example,
team
. - 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
.
Click Select when to evaluate
.
Enter example-repository
in the Repository field and click Include.
Click Add Filter and select Custom scope.
Enter a tag name and click Add Custom Scope.
Enter backend
in the team field and click Include.
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