هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

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/ Best Practices/ Building with Maven, Uploading the Software Package, and Pushing the Image to SWR (Built-in Executors, Code)

Building with Maven, Uploading the Software Package, and Pushing the Image to SWR (Built-in Executors, Code)

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

Scenario

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 practice, you build with Maven, upload the resulting software package to the release repo, and push the image to SWR.

These steps depend on the following services:

Requirements

  • You have created an organization named codeci_gray in SWR.
  • You have permissions for CodeArts Artifact.
  • You have permissions for CodeArts Repo.
  • You can only use the code hosted in CodeArts Repo for YAML builds.

Procedure

Table 1 Steps

Step

Description

Creating a Project

Create a project.

Creating a CodeArts Repo Repository

Create a CodeArts Repo repository to store code files.

Creating a build.yml File

Define the entire build process in build.yml.

Creating a Dockerfile

Customize an image by modifying the Dockerfile.

Creating a Build Task

Create a build task.

Viewing and Verifying the Build Results

View and verify the build results.

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 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 maven_yml_build in the Repository Name field, and leave the other parameters as default.
  5. Click OK. The repository details page is displayed.

Creating a build.yml File

  1. On the code repository details page, click Create and select Create Directory from the drop-down list, as shown in Figure 1.

    Figure 1 Creating a directory

  2. On the Create Directory page, set parameters based on Table 2 and click OK.

    Table 2 Creating a directory

    Parameter

    Description

    Directory Name

    Enter a directory name, 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.

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

    Figure 2 Creating a file

  5. 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 # The image path can be customized.
          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

  6. Click Submit.

Creating a Dockerfile

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

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

    server-1.0.jar combines the values of artifactId, packaging, and version in the pom.xml file.

  2. Click Submit.

Creating 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 3.

    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 Creating a CodeArts Repo Repository.

    Default Branch

    Keep the default value master.

    Description

    Enter additional information to describe the build task.

  3. Click Next. On the displayed page, select Blank Template. 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 in the upper right corner.

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 the 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.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback