Help Center/ CodeArts Build/ Best Practices/ Using the File From the Self-hosted Repo to Build with Maven and Uploading the Resulting Software Package (Built-in Executors, GUI)
Updated on 2024-10-10 GMT+08:00

Using the File From the Self-hosted Repo to Build with Maven and Uploading the Resulting Software Package (Built-in Executors, GUI)

Scenario

CodeArts Build provides default dependency repositories. If they fall short of your service needs, you can create custom repositories for Maven builds.

These steps depend on the following services:

Requirements

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

Procedure

Table 1 Steps

Step

Description

Creating a Project

Create a project.

Creating a Self-hosted Repo

Create a self-hosted repo.

Checking Information About the Self-hosted Repo

Check the ID and URL of the self-hosted repo, which will be used for configuring the pom.xml file of the code repository.

Uploading the settings.xml File to CodeArts Build

Upload the settings.xml file to Files for management in CodeArts Build.

Creating a CodeArts Repo Repository

Create a code repository.

Configuring the Self-hosted Repo Address for Storing Maven Build Products

Configure the address of the self-hosted repo where the build product will be uploaded.

Creating a Build Task

Create a build task.

Configuring Build Actions and Running the Build Task

Configure actions Download File from File Manager and Build with Maven, and run the build task.

Viewing the Build Results

View the build results stored in the self-hosted repo.

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 , and leave the other parameters as default.
  6. Click OK to access the project.

Creating a Self-hosted Repo

  1. In the navigation pane, choose Artifact > Self-hosted Repos.
  2. Click Create and set parameters according to the following table.

    Table 2 Parameters for creating a self-hosted repo

    Parameter

    Description

    Repository Type

    Select Local Repository.

    Repository Name

    Assign a custom name to the repository, for example, private_repository.

    Package Type

    Select Maven.

    Project

    Leave the value as default. The field is autofilled with build-bestpractice in this practice.

    Include Patterns

    Leave it blank.

    Version Policy

    Specify the version of artifacts stored in the repository. Select either Release (the release version with stable functions) or Snapshot (the development version with unstable functions). You can also select both of them if needed. In this practice, select Release.

    Description

    Enter additional information to describe the repository. Use no more than 200 characters.

  3. Click Submit. The details page of private_repository is displayed.

Checking Information About the Self-hosted Repo

  1. Click Tutorial in the upper right corner.
  2. In the displayed dialog box, click Download Configuration File, leaving the settings as default.
  3. In the dialog box that appears next, click Download.

    Figure 1 Downloading the configuration file

  4. Open the downloaded settings.xml file and navigate to the <profile> section that includes the <repositories> element. Under this element, find the <repository> block that contains information about the repository. Record the values of id and url.

    Figure 2 Checking the repository ID and URL

Uploading the settings.xml File to CodeArts Build

  1. In the navigation pane, choose CICD > Build.
  2. On the build task list page, choose More > Files.
  3. On the displayed page, click Upload File.
  4. In the displayed dialog box, upload the settings.xml file you download when checking information about the self-hosted repo. Select the check box to confirm that you have read and accept the agreements. Then click Save.

Creating a CodeArts Repo Repository

  1. In the navigation pane, choose Code > Repo.
  2. On the displayed page, click New Repository. Select Template, and click Next.
  3. On the template selection page, select the Java Maven Demo template and click Next.
  4. On the repository creation page, type private_repository_repo in the Repository Name field, and leave the other parameters as default.
  5. Click OK. Figure 3 shows the directory that stores files of the code repository.

    Figure 3 Directory

Configuring the Self-hosted Repo Address for Storing Maven Build Products

  1. Click the pom.xml file to enter its details page. In the right pane, Click to access the file editor.
  2. Copy the following sample code and add it under the build tag.

    Figure 4 Sample code of the pom.xml file
    <distributionManagement>
        <repository>
          <id>ID</id>
          <url>https://example/</url>
        </repository>
      </distributionManagement>

    Replace the placeholders of id and url (ID and https://example/) with the values of id and url recorded in 4.

  3. Click OK.

Creating a Build Task

  1. In the navigation pane, choose CICD > Build.
  2. Click Create Task. On the displayed Basic Information page, set the following parameters. Leave the other parameters as default.

    • Name: Assign a custom name to the build task, for example, private_repository_task.
    • Code Source: Select Repo.
    • Repository: Select private_repository_repo, the code repository created in Creating a CodeArts Repo Repository.

  3. Click Next. On the displayed page, select Blank Template.
  4. Click OK. The Build Actions page is displayed.

Configuring Build Actions and Running the Build Task

  1. Click Add Action. Add action Download File from File Manager. Leave Action Name and Tool Version as default. Expand the File Name drop-down list and select the settings.xml file uploaded to CodeArts Build.
  2. Click Add Action. Add action Build with Maven. In the Commands window, add a number sign (#) before the mvn package -Dmaven.test.skip=true -U -e -X -B command, delete the number sign before mvn deploy -Dmaven.test.skip=true -U -e -X -B, and change mvn deploy -Dmaven.test.skip=true -U -e -X -B to mvn deploy -Dmaven.test.skip=true -s settings.xml -U -e -X -B. Leave the other parameters as default.

    Figure 5 Command for packaging
    Figure 6 Command for releasing the dependencies

  3. Click Save and Run. In the displayed dialog box, click Confirm. Wait for the build task to complete.

Viewing the Build Results

  1. Click the build task name (private_repository_task is used in this practice).
  2. On the Build History tab page, click the build ID. On the displayed page, check the action logs. com/huawei/demo/javaMavenDemo/1.0 is the path of the uploaded build product in the self-hosted repo private_repository.

    Figure 7 Path for uploading dependencies

  3. In the navigation pane, choose Artifact > Self-hosted Repos.
  4. Expand private_repository and its subfolders. Find the uploaded software package at com/huawei/demo/javaMavenDemo/1.0.

    Figure 8 Checking the uploaded the software package