Using gate policies to ensure quality
A gate policy is a set of rules that can be used to ensure that a build meets certain quality criteria before being deployed to your chosen environment. Gates check if your test results comply with a defined policy. If the policy is not met, the DevOps Insights gate fails by default and the build will not deploy. You can also configure gates to act in an advisory role to allow pipeline progression even after failure.
IBM Cloud® DevOps Insights supports many popular formats for test data like unit tests, functional verification tests, and custom data sets, DevOps Insights supports JUnit or XUnit, and Mocha. For code coverage and custom data sets, DevOps Insights supports Cobertura, lcov, and JaCoCo. You can use any tool within your toolchain to run your unit tests, code coverage tests, functional verification tests, and then capture your test results in any one of the supported formats.
For more information about toolchains, see Creating a toolchain from an app. For more information about data sets, see Managing data sets.
To go to the Policy Rules page within DevOps Insights, complete the following steps:
- From the IBM Cloud console, click the Menu icon
> Platform Automation > Toolchains.
- On the Toolchains page, click your toolchain to open its Overview page.
- On the IBM Cloud tools card, click the DevOps Insights tool integration.
- From the menu, select Policies and then select a policy.
Gate decisions
In your pipeline, you can enter a command by using the IBM Cloud CLI to check the quality of a build against a predefined policy. When the policy is evaluated, you can check the decision in the DevOps Insights tool.
Build detail page
From the Risk Analysis page, you can view gate decision reports on the Build detail page. The Build detail page has information about your latest report.
- From the IBM Cloud console, click the Menu icon
> Platform Automation > Toolchains.
- On the Toolchains page, click your toolchain to open its Overview page.
- On the IBM Cloud tools card, click the DevOps Insights tool integration.
- From the menu, select Risk Analysis and then click the Application tab.
- From the table, select the application that you want to view and then select the build.
Decision report
You can also view data for particular decisions based on the policy assigned to a build. From the Build detail page, navigate to the Decision report page. Select View details from the Decisions for this build table for the policiy decision you want to view.
Defining policies and rules
A policy is a set of rules that you can customize, and a rule is the passing criteria that you define for each type of test data you upload. Policy rules can be evaluated by gates. Gates are the mechanism that is implemented in continuous integration and continuous delivery (CI/CD) tools to hold back your build if it doesn't meet the passing threshold. If your code doesn't meet or exceed a policy that is enacted at a particular gate, the deployment is stopped to prevent risky changes from being promoted to the next environment.
Creating policies and rules
A policy is a set of rules that define the criteria that your gate uses to determine whether a build will be promoted to the next stage in a CI/CD tool. For example, you can create a policy that contains a unit test rule that requires 100 percent success and a test coverage rule that requires 80 percent coverage. A gate refers to this policy to prevent builds that don't satisfy both rules from proceeding.
To create a policy, complete the following steps:
- From the IBM Cloud console, click the Menu icon
> DevOps.
- On the Toolchains page, select your toolchain.
- From your toolchain's Overview page, on the IBM Cloud tools card, click DevOps Insights.
- Select Policies.
- Click Create Policy.
- Complete all of the required fields, and click Next.
- Click Create Rule.
- Complete all of the required fields.
- Optional. Select the Regression Check box to opt out of test case regression. This option is available only for data sets, Unit Tests, Code Coverage, and Functional Verification Tests.
- Click Save.
If you want to add another rule, repeat from step 3.
For more information about data sets, see Managing data sets.
Adding a rule to an already established policy
You can add rules to policies that are already defined.
- From the Policies page, select the policy to add the rule.
- Click Create Rule.
- Complete all required fields, then click Save.
Editing rules
You can edit the rules that you established with your policies. You can change the rule description, the results file format, and the minimum code coverage required.
To edit rules, complete the following steps:
- From the Policies page, select the policy that has the rule you want to edit.
- Click the Edit icon
for the rule.
- Complete all required fields, and click Save.