Help Center/ CodeArts Pipeline/ Best Practices/ Configuring Pass Conditions for Automated Code Checks
Updated on 2024-11-08 GMT+08:00

Configuring Pass Conditions for Automated Code Checks

Overview

Traditional software quality relies mainly on manual tests, leading to low efficiency.

CodeArts Pipeline uses pass conditions to control whether a pipeline can proceed to the next stage. You can apply policies to pipelines as pass conditions for efficient project management and high-quality delivery.

With CodeArts Pipeline, more than 70% issues can be intercepted through automated code checks. This improves test efficiency and software quality.

Procedure

The following describes how to configure code check thresholds and apply pass conditions to a stage for automated check.

Figure 1 Pipeline workflow

Perform the following procedure.

Table 1 Procedure

Step

Description

Create a rule and configure thresholds

Create a rule of the code check type and configure thresholds for the rule.

Create a policy and add the rule to the policy

Add the preceding code check rule to the created policy.

Configure a pipeline

Add the preceding policy to the pass conditions.

Execute the pipeline

Execute the pipeline:

  • If the code check job meets the pass conditions, the pipeline will continue to run.
  • If the code check job does not meet the pass conditions, the pipeline will stop running.

Preparations

  • You have created a project. The following uses a Scrum project named Project01 as an example.
  • You have created a code repository. The following uses a repository named Repo01 (created using the Java Maven Demo template) as an example.

    A code check task with the same name as the code repository is automatically created. Change the task name to CheckTask01 by referring to Configuring Basic Info.

  • You have created a build task with the Repo01 repository. The following uses a build task (created using the Maven template) named BuildTask01 as an example.
  • You have created a pipeline with the Repo01 repository. The following uses a pipeline named Pipeline01 (created using the blank template) as an example.

Step 1: Create a Rule and Configure Thresholds

  1. Log in to the Huawei Cloud console.
  2. Click in the upper left corner of the page and choose Developer Services > CodeArts Pipeline from the service list.
  3. Click Access Service.
  4. Click the avatar icon in the upper right corner and choose All Account Settings from the drop-down list.
  5. In the navigation pane on the left, choose Policy Management > Rules.
  6. Click Create Rule. On the displayed page, configure parameters.

    Figure 2 Creating a rule
    Table 2 Rule parameters

    Parameter

    Description

    Name

    Enter a rule name, such as Check_code.

    Type

    Select the rule type Check.

    Extension

    Select the extension Check.

    Version

    Select the version 0.0.1.

    Threshold Configuration

    The extension thresholds are automatically filled based on the selected extension version. You can use the default values.

  7. Click OK.

Step 2: Create a Policy and Add a Rule to the Policy

There are tenant-level policies and project-level policies. Tenant-level policies can be applied to pipelines of all projects under the current tenant, while project-level policies can be applied to all pipelines under the current project. The following uses a tenant-level policy as an example.

  1. In the navigation pane on the left, choose Policies.

    A system policy exists by default. You can view and use the policy, but cannot edit or delete it.

  2. Click Create Policy. On the displayed page, enter a policy name and select the rule created in Step 1: Create a Rule and Configure Thresholds.

    Figure 3 Creating a policy

  3. Click OK.

Step 3: Configure a Pipeline

  1. On the top navigation bar, click Homepage.
  2. Search for the project created in Preparations and access the project.
  3. In the navigation pane on the left, choose CICD > Pipeline.
  4. Search for the pipeline created in Preparations, click in the Operation column, and select Edit. The Task Orchestration page is displayed.
  5. Click under Stage_1, add the code check job created in Preparations, and set Check Mode to Full.

    Figure 4 Adding a code check job

  6. Click under Stage_1, on the displayed window, add Pass-Conditions-of-Standard-Policies, and select the policy created in Step 2: Create a Policy and Add a Rule to the Policy.

    Figure 5 Adding pass conditions

  7. Click or to add a new stage for the pipeline, add the build job created in Preparations, and select the associated repository for the build job.

    Figure 6 Adding a build job

Step 4: Execute the Pipeline

  1. After configuring the pipeline, click Save and Execute.
  2. Check the execution result.

    • If the code check job meets the pass conditions, the pipeline will proceed to the next stage, as shown in the following figure.
      Figure 7 Executing a pipeline
    • If the code check job does not meet the pass conditions, the pipeline will stop running, as shown in the following figure. You can click the pass conditions card to check details.