Help Center/ CodeArts Pipeline/ Best Practices/ Transferring CodeArts Pipeline Parameters to CodeArts Build and CodeArts Deploy
Updated on 2024-11-08 GMT+08:00

Transferring CodeArts Pipeline Parameters to CodeArts Build and CodeArts Deploy

Overview

Pipeline parameters can be transferred among different services (such as CodeArts Build and CodeArts Deploy). By creating a CI/CD pipeline, you can streamline data of build and deployment.

Procedure

The following describes how to transfer a pipeline version number parameter to a build and a deployment job.

Step 1: Create a Build Task

Step 2: Create an application

Step 3: Create and Execute a Pipeline

Step 4: Check Build and Deployment Results

Table 1 Procedure

Step

Description

Create a build task

Create a build task, add the version number parameter, and reference it in the build step.

Create an application

Create an application, add a software package parameter, and reference it in the deployment step.

Create and execute a pipeline

Create a pipeline, add the version number parameter, and add the created build task and application to the pipeline.

  • In the build task, reference the pipeline version number parameter.
  • In the application, reference the pipeline version number parameter.

Check the build and deployment results

Check whether:

  • The build package version number is a dynamic parameter transferred by the pipeline.
  • The software package has been obtained by the deployment job.

Preparations

Step 1: Create a Build Task

  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 Homepage from the top navigation pane.Search for the project created in Preparations and access the project.
  5. In the left navigation pane, choose CICD > Build.
  6. Click Create Task and enter basic information.

    Table 2 Basic information

    Parameter

    Description

    Name

    Build task name. Enter BuildTask01.

    Project

    Keep the default value, which is the project of the build task.

    Code Source

    Code source associated with the build task. Select Repo.

    Repository

    Select the repository Repo01 created in Preparations.

    Default Branch

    Select master.

  7. Click Next, select the Maven template, and then click OK.
  8. On the Parameters tab page, add the releaseversion parameter, set the default value, and enable Runtime Settings.

    Figure 1 Creating a build parameter

  9. On the Build Actions page, click Upload Software Package to Release Repository. For the Version field, enter ${releaseversion}, and retain the default values for other fields.

    Figure 2 Configuring build actions

  10. Click Save.

Step 2: Create an application

  1. In the left navigation pane, choose Settings > General > Basic Resources, create a host cluster, and add the purchased host to the cluster.
  2. In the left navigation pane, choose CICD > Deploy.
  3. Click Create Application. On the displayed page, enter an application name DeployTask01, click Next, select Blank Template, and click OK.
  4. On the Parameters tab page, add the package_url parameter, set the default value, and enable Runtime Settings.

    Figure 3 Creating a deployment parameter

  5. On the Environment Management page, click Create Environment, enter the name Environment01, and import the host in the cluster to the environment.
  6. On the Deployment Actions tab page, add the Select Deployment Source action and configure the information as shown in the following table.

    Figure 4 Configuring deployment actions
    Table 3 Configuring deployment actions

    Parameter

    Description

    Action Name

    Retain the default value.

    Source

    Software package source. Select Artifact.

    Environment

    Environment for deployment. Select Environment01.

    Software Package

    Software package to be deployed. Obtain the build package uploaded by the build task to Release Repos. Set this parameter to ${package_url} to reference the package_url parameter.

    Download Path

    Path for downloading the software package to the target host. Enter /usr/local.

    Action Control

    Retain the default setting.

  7. Click Save.

Step 3: Create and Execute a Pipeline

  1. In the navigation pane on the left, choose CICD > Pipeline.
  2. Click Create Pipeline and configure pipeline information.

    1. Configure the following basic information and click Next.
      Table 4 Pipeline basic information

      Parameter

      Description

      Name

      Enter Pipeline01.

      Code Source

      Code source associated with the pipeline. Select Repo.

      Repository

      Select the repository Repo01 created in Preparations.

      Default Branch

      Select master.

    2. Select Blank Template and click OK.

  3. On the Parameter Configuration tab page, create the releaseversion parameter, set its default value to ${TIMESTAMP}, and enable Runtime Setting.
  4. On the Task Orchestration page, two stages (Code Source and Stage_1) are generated by default. Click Stage to add a new stage (Stage_2).

    Figure 5 Task orchestration
    1. Add a build job
      1. Click New Job under the Stage_1.
      2. Click the Build type and search for the Build extension.
      3. Move the cursor to the Build extension, click Add, select the created build task, select the repository associated with build task, and set releaseversion to ${releaseversion} to reference the releaseversion parameter of the pipeline.
      Figure 6 Adding a build job
    2. Add an application
      1. Click Job under Stage_2.
      2. In the displayed dialog box, search for the Deploy extension.
      3. Move the cursor to the Deploy extension, click Add, select the created application, enter the package path for package_url, and associate with the added build task, as shown in the following figure.
      Figure 7 Adding an application

      package_url is the relative path of the build package in Release Repos. The path includes the build task name, version number, and package name. In this section, the pipeline releaseversion parameter indicates the version number.

  5. Click Save and Execute.

Step 4: Check Build and Deployment Results

After the pipeline is successfully executed, check whether the pipeline parameter has been transferred to the build and deployment jobs.

  • Check the build result
    1. In the navigation pane on the left, choose Artifact > Release Repos.
    2. Expand the project navigation tree on the left to check the uploaded build package.
      As shown in the following figure, the version number in the relative path is the timestamp transferred by the pipeline releaseversion parameter.
      Figure 8 Checking the software package
  • Check the deployment result
    1. Click the user name in the upper right corner.
    2. Click CodeArts Console.
    3. Click in the upper left corner and search for Elastic Cloud Server. Then, access the Elastic Cloud Server console.
    4. Locate the ECS used for deployment, click Remote Login in the Operation column.
    5. In the Other Login Modes area, select Log in using Remote Login on the management console and click Log In.
    6. Enter the username and password for purchasing the ECS. Press Enter.
    7. Enter the following command and press Enter to go to the directory /usr/local configured during the Create an Application step.
      cd /usr/local
    8. Enter the following command and press Enter. The deployed build package is displayed as shown in the following figure, which indicates that the pipeline parameter has been successfully transferred.
      ls -al
      Figure 9 Checking the deployment result