Help Center/ CodeArts Build/ Best Practices/ Building with Maven (Custom Executors, GUI)
Updated on 2024-11-21 GMT+08:00

Building with Maven (Custom Executors, GUI)

Scenario

If the built-in executors provided by CodeArts Build fall short of your service needs, you can use your own computing resources. Once registered, these computing resources can be hosted in CodeArts Build. You can then configure CodeArts Build to schedule them for running build tasks. In this practice, you configure actions Build with Maven and Upload to Release Repo and run your build on custom executors.

These steps depend on the following services:

Requirements

  • You have permissions for CodeArts Artifact.
  • You have permissions for CodeArts Repo.

Prerequisites

You have purchased an Elastic Cloud Server (ECS) for your custom executors by referring to Purchasing an ECS.

Procedure

Table 1 Steps

Step

Description

Creating a Project

Create a project.

Creating an Agent Pool

Create a pool of custom executors (agent pool).

Creating a CodeArts Repo Repository

Create a repository to store code.

Creating and Running a Build Task

Create a build task that includes actions Build with Maven and Upload to Release Repo.

Viewing the Build Task and Its Result

Check the build logs to verify the executors used for the build task and view the uploaded software package in CodeArts Artifact.

Creating a Project

  1. Log in to the Huawei Cloud console with your Huawei Cloud account.
  2. Click in the upper left corner and choose Developer Services > CodeArts from the service list.
  3. Click Access Service. The homepage of CodeArts is displayed.
  4. Click Create Project, and select the Scrum template.
  5. Set the project name to build-bestpractice, and leave the other parameters as default.
  6. Click OK to access the project.

Creating an Agent Pool

  1. On the navigation bar, click the username and choose All Account Settings.
  2. Choose Agent Management > Agent Pool.
  3. Click Create Pool. In the displayed dialog box, set parameters according to Table 2 and click Save.

    Table 2 Agent pool configuration

    Parameter

    Description

    Pool Name

    Assign a custom name to the pool, for example, custom_pool.

    Pool Type

    Select LINUX_DOCKER. When a task is initiated, a Linux Docker container will be started to run the task.

    Description

    (Optional) Enter additional information to describe the pool.

    This pool can be used by all users of the current account.

    (Optional) Selecting this option allows all users within the current account to use the pool.

  4. Click the name of the new pool (custom_pool is used in this practice). The pool configuration page is displayed.
  5. Click Create Agent. In the displayed dialog box, configure the agent according to Table 3 and leave the other parameters as default.

    Table 3 Parameters for creating an agent

    Parameter

    Description

    Install Docker

    Selecting this option mandates Docker installation.

    Install Docker automatically

    Toggling on the switch will automatically install Docker.

    AK

    Obtain the AK by referring to Obtaining an AK/SK.

    SK

    Obtain the SK by referring to Obtaining an AK/SK.

    Agent Name

    Assign a custom name to the agent, for example, agent_test_custom.

    Agent Workspace

    Enter an agent workspace that follows the standard Linux directory structure. For example, /opt/agent_test_custom.

  6. Select the check box to confirm that you have read and accept the agreements. Then click Generate Command and Copy Command. Click Close.

    Figure 1 Creating an agent

  7. Go to the ECS list page, find the row of the ECS purchased to meet prerequisites, click Remote Login, and run the command copied in 6, as instructed by Step 3.
  8. On the agent list page, click Refresh List. After the information is automatically synchronized in the background, a new item will be added to the list. The agent alias is agent_test_custom-mwlye1NlLG.

Creating a CodeArts Repo Repository

  1. On the navigation bar, choose Services > Repo. The CodeArts Repo homepage is displayed.
  2. Click New Repository. On the displayed page, expand the Project drop-down list and select the project name you specify when creating a project. Then, select Template as the repository type. Click Next.
  3. On the template selection page, select the Java Maven Demo template and click Next.
  4. On the displayed page, set Repository Name to custom_repo, and leave the other parameters as default. Click OK.

    Figure 2 shows the directory that stores files of the code repository.

    Figure 2 Directory that stores files of the code repository

Creating and Running a Build Task

  1. In the navigation pane, choose CICD > Build.
  2. Click Create Task. On the displayed Basic Information page, set parameters according to Table 4. Then, click Next.

    Table 4 Basic information

    Parameter

    Description

    Name

    Assign a custom name to the build task, for example, custom_task.

    Code Source

    Select Repo to pull the code hosted in a CodeArts Repo repository for your build.

    Repository

    Select custom_repo, the code repository created in Creating a CodeArts Repo Repository.

    Default Branch

    Keep the default value master.

    Description

    Enter additional information to describe the build task.

  3. Select the Maven template and click OK. The Build Actions page is displayed.
  4. Configure the build environment according to the following table. Leave the other parameters as default, and click Save and Run.

    Table 5 Environment parameters

    Parameter

    Description

    Execution Host

    Select Custom executor.

    Agent Pool

    Expand the drop-down list and select custom_pool you created in section "Creating an Agent Pool".

    Figure 3 Configuring the build environment

  5. In the displayed dialog box, click Confirm. The build task run page is displayed.

Viewing the Build Task and Its Result

  1. The console displays the logs of the build task as it runs. The log window automatically scrolls down to show new entries. As shown in Figure 4, the log indicates that the current build task is running on executor agent_test_custom-mwlye1NlLG in pool custom_pool created in section Creating an Agent Pool.

    Figure 4 Build logs

  2. The build task is considered successful if each build action is marked with after running.

    Figure 5 Build success

  3. Click action Upload to Release Repo. In the logs, you can find the path that stores the software package uploaded to the release repo: /custom_task/20240620.19/.
  4. In the navigation pane, choose Artifact > Release Repos. You can find the software package at /custom_task/20240620.19/javaMavenDemo-1.0.jar.

    Figure 6 Software package information