El contenido no se encuentra disponible en el idioma seleccionado. Estamos trabajando continuamente para agregar más idiomas. Gracias por su apoyo.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ CodeArts Build/ Getting Started/ Building with Maven, Uploading the Software Package, and Pushing the Image (x86, Preset Image, Code)

Building with Maven, Uploading the Software Package, and Pushing the Image (x86, Preset Image, Code)

Updated on 2024-11-21 GMT+08:00

CodeArts Build allows you to define your build as code using YAML. Your configurations, such as build environments, parameters, commands, and actions, reside in a YAML file (named build.yml in this practice). After creating this file, add it along with the source code to a code repository. The file will be used as a script by the system to run a build, making the process traceable, recoverable, secure, and reliable.

In this section, you define your Maven build as code, build your project using the x86 server and the preset image, upload the resulting software package to the release repo, and push the image to SoftWare Repository for Container (SWR).

Prerequisites

  • You have registered with Huawei Cloud and completed real-name authentication. If you do not have a HUAWEI ID yet, follow these steps to create one:
    1. Visit Huawei Cloud official website.
    2. Click Sign Up and create your account as instructed.

      Once your account is created, the system automatically redirects you to your personal information page.

    3. Complete individual or enterprise real-name authentication. For details, see Real-Name Authentication.
  • You have enabled CodeArts Free Edition. If not, enable it by referring to Purchasing a CodeArts Package.
  • You have created an organization in SWR. If no organization is available, create one by referring to Creating an Organization.

Preparing 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 Build from the service list.
  3. Click Access Service. The homepage of CodeArts Build is displayed. On the navigation bar, click Homepage.
  4. Click Create Project, and select the Scrum template. Set the project name to Scrum01 and keep the default values for other parameters. Click OK to access the project.

Creating a CodeArts Repo Repository

  1. In the navigation pane, choose Code > Repo.
  2. On the displayed page, click New Repository. Select Common, and click Next.
  3. Set parameters according to Table 1 and click OK.

    Table 1 Creating a code repository

    Parameter

    Description

    Repository Name

    Assign a custom name to the code repository, for example, maven_yml_build.

    • The name starts with a digit, letter, or underscore (_).
    • The name can contain periods (.) and hyphens (-).
    • The name cannot end with .git, .atom, or a period (.).

    Description

    (Optional) Enter additional information to describe the code repository. Max. 2,000 characters.

    .gitignore Programming Language

    Select the appropriate programming language, such as Java, for the .gitignore file.

    Initial Settings

    Select all.

    • Allow project members to access the repository: Select this option to auto-assign a project manager as the repository administrator, and a developer as a common repository member. Once these roles are added to the project, they will be automatically synced with existing repositories.
    • Generate README: Select this option to create a README file where you can add details about the project's architecture and purpose, similar to a repository-wide comment.
    • Automatically create check task (free of charge): Select this option to auto-generate a code check task for the repository upon creation. The check task will appear in the check task list.

    Visibility

    Select Private to make the repository visible only to its members. These members can access the repository and commit code.

Creating a build.yml File

  1. In the navigation pane, choose Code > Repo.
  2. Click the name of the code repository you created (see Creating a CodeArts Repo Repository).
  3. Click Create and select Create Directory from the drop-down list, as shown in Figure 1.

    Figure 1 Creating a directory

  4. Set parameters according to Table 2 and click OK.

    Table 2 Creating a directory

    Parameter

    Description

    Directory Name

    Assign a custom name to the code directory, for example, .cloudbuild. Use 1 to 100 characters, including letters, digits, slashes (/), underscores (_), hyphens (-), and periods (.).

    Commit Message

    Describe the files within the directory. Use 1 to 2,000 characters.

  5. Click the name of the directory created in Step 4.
  6. Click Create and select Create File from the drop-down list, as shown in Figure 2.

    Figure 2 Creating a file

  7. Name the file build.yml and copy the following code to the file:

    # The YAML provided is a default template that can be edited as needed.
    ---
    version: 2.0
    steps:
      BUILD:
      - maven:
          image: cloudbuild@maven3.5.3-jdk8-open
          inputs:
            settings:
              public_repos:
                - https://mirrors.huawei.com/maven
            cache: true # Determine whether to enable caching.
            command: mvn package -Dmaven.test.failure.ignore=true -U -e -X -B
      - upload_artifact:
          inputs:
            path: "**/target/*.?ar"
      - build_image:
          inputs:
            organization: codeci_gray # Organization name
            image_name: maven_demo # Image name
            image_tag: 1.0 # Image tag
            dockerfile_path: ./Dockerfile

  8. Click OK.

Creating a Java File

  1. Create a directory named src/main/java by referring to 4.
  2. Create a file named HelloWorld.java in the src/main/java directory by referring to 6 and 7. The code in the file is as follows:

    /**
     * Hello world
     *
     */
    
    public class HelloWorld {
    
      public static void main(String[] args) {
        System.out.println("Hello World!");
      }
    
    }

  3. Click OK.

Creating a Dockerfile

  1. In the root directory, create a file named Dockerfile by following 6 and 7. The code in the file is as follows:

    FROM swr.regionid.myhuaweicloud.com/codeci/special_base_image:centos7-base-1.0.2-in
    MAINTAINER <devcloud@demo.com> 
    USER root 
    RUN mkdir /demo 
    COPY ./target/server-1.0.jar /demo/app.jar

  2. Click OK.

Creating a pom.xml File

  1. In the root directory, create a file named pom.xml by following 6 and 7. The code in the file is as follows:

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.huawei.demo</groupId>
      <artifactId>server</artifactId>
      <packaging>jar</packaging>
      <version>1.0</version>
      <name>server</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
      </dependencies>
    
    
      <build>
        <pluginManagement>
          <plugins>
            <plugin>  
              <groupId>org.apache.maven.plugins</groupId>  
              <artifactId>maven-jar-plugin</artifactId>  
              <version>2.6</version>  
              <configuration>  
                <archive>  
                  <manifest>  
                    <addClasspath>true</addClasspath>  
                  </manifest>  
                  <manifestEntries>  
                    <Main-Class>  
                      HelloWorld
                    </Main-Class>  
                  </manifestEntries>  
                </archive>  
              </configuration>  
            </plugin> 
          </plugins>
        </pluginManagement>
      </build>
    </project>

  2. Click OK.

Creating a Build Task

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

    Table 3 Basic information

    Parameter

    Description

    Name

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

    Code Source

    Select Repo.

    Repository

    Select Repo01, the code repository created in section "Creating a CodeArts Repo Repository".

    Default Branch

    Select the branch created in section "Creating a CodeArts Repo Repository". Keep the default value master.

  3. Select Blank Template and click OK. The Build Actions page is displayed.
  4. Click the Code tab. Then you can view the imported build script, as shown in Figure 3.

    Figure 3 Code tab

  5. Click Save and Run.

Viewing and Verifying the Build Results

  • Checking the uploaded the software package
    1. In the navigation pane, choose Artifact > Release Repos.
    2. On the displayed page, find the folder that shares the same name as the build task (the name you specify when creating a build task), as shown in Figure 4. The software package can be found within this folder.
      Figure 4 Checking the software package
  • Checking the pushed image
    1. Go to the SWR console.
    2. In the navigation pane, choose My Images. In the search box, select Organization as the filter field, and type the organization name (codeci_gray is used in this example) you configure when creating a build.yml file.
    3. In the filtered results, click the image name (maven_demo is used in this example) you configure when creating a build.yml file, as shown in Figure 5.
      Figure 5 Filtering images

Utilizamos cookies para mejorar nuestro sitio y tu experiencia. Al continuar navegando en nuestro sitio, tú aceptas nuestra política de cookies. Descubre más

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback