Help Center/ CodeArts Pipeline/ Best Practices/ Creating Tags for Code Repositories Through Pipelines
Updated on 2025-08-28 GMT+08:00

Creating Tags for Code Repositories Through Pipelines

Overview

Contexts are a way to access information about pipeline runs, sources, variables, and jobs. Each context is an object that contains various attributes. You can use pipeline contexts to transfer information among jobs to streamline a pipeline.

The following describes how to create a repository tag through the pipeline contexts.

Preparations

Procedure

  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 Create Pipeline and configure parameters by referring to Table 1.

    Table 1 Pipeline basic information

    Parameter

    Description

    Name

    Pipeline name. Enter a maximum of 128 characters, including letters, digits, underscores (_), and hyphens (-). For example, Pipeline-Test.

    Project

    Project to which the pipeline belongs. Select the project Project_Test created in Preparations.

    Code Source

    Code source associated with the pipeline. Select Repo.

    Repository

    Code repository associated with the pipeline. Select the code repository Repo_Test created in Preparations.

    Default Branch

    Select the branch release-1.0.0 created in Preparations.

  5. After configuring the basic information, click Next. On the displayed Select Template page, select Blank Template and click OK.
  6. Access the Task Orchestration page. Two stages (Pipeline Source and Stage_1) are generated by default. Click Stage to add a new stage (Stage_2).
  7. Click New Job under Stage_1 and select From empty. In the displayed window, search for the ExecuteShellCommand extension, move the cursor to this extension, click Add, retain the default name, and enter the following shell command to generate a tag name:

    1
    2
    3
    4
    5
    branch='${{ sources.Repo_Test.target_branch }}'    //Obtain the name of the running branch.
    echo $branch                                    //Print the branch name.
    tag=${branch/release-/v}                        //Rename the branch. (Here we customize the branch name release-1.0.0 as v1.0.0.)
    echo $tag                                       //Print the tag name.
    echo ::set-output var=tag_name:$tag             //Generate an output tag_name and set it as a context for future use.
    
    Figure 1 Generating a tag name

  8. Click Job under Stage_2 and select From empty. In the displayed window, search for the CreateTag extension, move the cursor to this extension, click Add, and set parameters by referring to Table 2.

    Table 2 Parameter description

    Parameter

    Description

    Name

    Retain the default name.

    Tag Name

    Enter ${{jobs.JOB_tBeer.outputs.tag_name}}, where JOB_tBeer indicates the task ID of the added ExecuteShellCommand extension.

    Repository

    Select the code repository associated with the pipeline.

    Figure 2 Creating a repository tag

  9. After the configuration is complete, click Save and Execute. In the displayed window, retain the default settings and click Execute.
  10. After the pipeline execution is complete, choose Code > Repo from the left navigation pane.
  11. Click the repository associated with the pipeline.
  12. On the displayed Code page, click the Tags tab. The tag v1.0.0 is displayed.

    Figure 3 Checking a tag