Help Center/ CodeArts Pipeline/ Best Practices/ Controlling the Release Time with a Custom Extension
Updated on 2025-11-26 GMT+08:00

Controlling the Release Time with a Custom Extension

Overview

Define the input, script, and output for a custom extension to implement specific service logic in CodeArts Pipeline. A custom extension can be reused in multiple pipelines. CodeArts Pipeline provides many official extensions and allows you to customize extensions as needed. This section describes how to create a custom extension to control the release time. The process includes defining parameters, input, output, and applying the output to the pipeline pass conditions based on rules and policies.

Pipeline gates are checkpoints set during pipeline execution. They ensure that a pipeline can proceed only when specific conditions are met. In this section, we use a custom extension and pipeline gate to control the release time. If you manually execute the pipeline earlier than the safe release time, the pipeline fails to pass the gate.

Preparations

Step 1: Create a Custom Extension

  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. On the top navigation bar, choose Services > Extensions.
  5. Click . On the displayed page, enter basic information by referring to Table 1.

    Table 1 Extension information

    Parameter

    Example Value

    Description

    Icon

    -

    Icon of the extension. Upload an image in PNG, JPEG, or JPG format, with a file size no more than 512 KB (recommended: 128 x 128 pixels). If no image is uploaded, the system generates an icon.

    Name

    Release Time Control

    Extension name displayed in the extension platform. Enter a maximum of 50 characters. Only spaces, letters, digits, underscores (_), hyphens (-), and periods (.) are allowed.

    Unique Identifier

    ReleaseTimeControl

    Unique identifier of the extension. Once set, the value cannot be changed.

    Type

    Normal

    Extension type, which can be Build, Check, Test, Deploy, or Normal. Once set, this parameter cannot be changed.

    Description

    -

    Describes how to use the extension.

  6. After configuring the basic information, click Next. On the Version Info page, use the default version number.
  7. Click Next. The Input page is displayed. Drag the Single-line Text Box widget from the left side to the canvas. Configure the widget information by referring to Table 2.

    Table 2 Widget information

    Type

    Parameter

    Description

    Basic

    Unique Identifier

    Enter safe_release_time.

    Title

    Enter Safe release time.

    Tips

    Enter Earliest release time in 24-hour format, for example, 193000, indicating that the earliest release time is 19:30:00.

    Placeholder

    Enter Earliest release time in 24-hour format, for example, 193000.

    Verification

    Mandatory

    Enabled

    RegEx Validation

    Enter ^\d{6}$.

  8. Click Next. On the displayed Orchestration page, add the ExecuteShellCommand extension. Enter the shell command by referring the following example to generate a tag name.

    # Extract the hour, minute, and second of the safe release time.
    safe_hour="${safe_release_time:0:2}"
    safe_minute="${safe_release_time:2:2}"
    safe_second="${safe_release_time:4:2}"
     
    # Verify the time validity.
    if [[ "$safe_hour" -gt 23 || "$safe_minute" -gt 59 || "$safe_second" -gt 59 ]]; then
        echo "Error: safe_time contains invalid values."
        echo "ALLOW_RELEASE=false"
        exit 1
    fi
     
    # Obtain the current time (24-hour format).
    current_time=$(date +%H%M%S)
    current_hour=$(date +%H)
    current_minute=$(date +%M)
    current_second=$(date +%S)
     
    echo "Current time: $current_time"
    echo "Safe time: $safe_time"
    # PIPELINE_TRIGGER_TYPE is a predefined variable.
    echo "Pipeline trigger type: $PIPELINE_TRIGGER_TYPE"
     
    # Judgment logic
    if [[ "$PIPELINE_TRIGGER_TYPE" != "Manual" ]]; then
        # Automatic trigger - Allow release
        echo "Automatic trigger. Allow release"
        ALLOW_RELEASE="true"
    else
        echo "Manual trigger. Check whether the current time is after the safe release time..."
        
        # Convert the time to seconds for comparison.
        current_total_seconds=$((10#$current_hour * 3600 + 10#$current_minute * 60 + 10#$current_second))
        safe_total_seconds=$((10#$safe_hour * 3600 + 10#$safe_minute * 60 + 10#$safe_second))
        
        if [[ $current_total_seconds -ge $safe_total_seconds ]]; then
            echo "Check passed: The current time is after the safe release time. Release is allowed."
            ALLOW_RELEASE="true"
        else
            echo "Check failed: The current time is before the safe release time. Release is not allowed."
            ALLOW_RELEASE="false"
        fi
    fi
     
    echo "ALLOW_RELEASE=$ALLOW_RELEASE"
    # Output the result to the task gate output of the extension.
    echo ::set-metrics var=ALLOW_RELEASE:$ALLOW_RELEASE

  9. Click Next. The Output page is displayed. Click Add Configuration and set parameters by referring to Table 3.

    Table 3 Configuration information

    Parameter

    Example Value

    Description

    Key

    ALLOW_RELEASE

    Output of the script. The output variable is parsed through the key.

    Type

    metric

    metric: displayed on the Others card. It outputs metric thresholds. The thresholds information can be referenced in an extension and finally applied to pipelines.

    Description

    Whether the version can be released

    The description is displayed as a check item in the threshold configuration when you configure rules.

    Group Name

    Release time

    Category name.

  10. Click Release Draft in the upper right corner. In the displayed window, click Release Draft.
  11. On the displayed Version Management page, click to officially release the draft.

Step 2: Create a Rule and Policy for the Custom Extension

  1. Click the avatar icon in the upper right corner and choose All Account Settings from the drop-down list.
  2. In the navigation pane on the left, choose Policy Management > Rules.
  3. Click Create Rule. On the displayed page, configure parameters by referring to the following figure.

  4. Click Confirm. A message is displayed, indicating that the rule is created.
  5. In the navigation pane on the left, choose Policy Management > Policies.
  6. Click Create Policy and set parameters by referring to the following figure.

  7. Click Confirm. A message is displayed, indicating that the policy is created.

Step 3: Use the Custom Extension and Release Policy in 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, and select Edit. The Task Orchestration page is displayed.
  5. Click Create Job under Stage_1, search for and add the Release Time Control extension created in Step 1, set parameters by referring to the following figure, and click OK.

  6. Click Pass Conditions under Stage_1. In the displayed window, move the cursor to the Pass-Conditions-of-Standard-Policies card and click Add.
  7. Select the policy created in Step 3 and click OK.
  8. Click Save and Execute. In the displayed window, retain the default settings and click Execute.
  9. Verify the execution result.