Halaman ini belum tersedia dalam bahasa lokal Anda. Kami berusaha keras untuk menambahkan lebih banyak versi bahasa. Terima kasih atas dukungan Anda.

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/ Running a Multi-Task Maven Build Project (Built-in Executors, Code)

Running a Multi-Task Maven Build Project (Built-in Executors, Code)

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

Scenario

A build task is the smallest unit that a build project can be broken down into for simple service scenarios. However, for more complex requirements, you may need to set up multiple build tasks in a modular and fine-grained way, and run them in a specific order. This means that each task depends on the successful completion of its dependency task.

To handle such complex builds, CodeArts Build offers a task model called BuildFlow, which organizes multiple build tasks in a directed acyclic graph (DAG) and runs them in parallel based on their dependencies.

In this practice, your build project involves three build tasks (Job1, Job2, and Job3). Job3 depends on Job1 and Job2. Your code is stored in CodeArts Repo repositories.

Requirements

  • You can only use the code hosted in CodeArts Repo for a BuildFlow task.
  • You have permissions for CodeArts Repo.

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 Task Scripts Used in build.yml

Create a script for the whole build.

Creating and Running a Build Task

Create and run a build flow task.

Viewing the Build Results

View 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 displayed page, set Repository Name to Repo01 and keep the default values for other parameters.
  5. Click OK.

Creating a build.yml File

  1. On the code repository details page, click Create and select Create Directory from the drop-down list.
  2. Name the directory as .cloudbuild and describe the files it contains. Click OK.
  3. In the .cloudbuild directory, click Create and select Create File from the drop-down list. Name the file as build.yml and add the following code to the file:

    version: 2.0 # The version number is a mandatory and unique parameter that must be set to 2.0.
    params: # Parameters that can be referenced by builds.
      - name: condition_param
        value: 1
    # The envs configuration is optional.
    envs: 
      - condition: condition_param == 0 # The following host specification and type are not used if this condition is not met.
        resource:
          type: docker 
          arch: ARM
      - condition: condition_param == 1 # The following host specification and type are used if this condition is met.
        resource:
          type: docker
          arch: X86
    
    buildflow:
      jobs: # Build tasks
        - job: Job3 # Define the task name.
          depends_on: # Define the task dependency. In this practice, the configuration indicates that Job3 depends on Job1 and Job2.
            - Job1
            - Job2
          build_ref: .cloudbuild/build_job3.yml # Define the YAML build script to run for Job3.
        - job: Job1
          build_ref: .cloudbuild/build_job1.yml # Define the YAML build script to run for Job1.
        - job: Job2
          build_ref: .cloudbuild/build_job2.yml # Define the YAML build script to run for Job2.

    build.yml defines the entire build process, with three build tasks currently specified. Job3 depends on Job1 and Job2 and will be run only after they are completed. Job1 and Job2 have equal priority and will be triggered at the same time. build_ref defines the build script to be run for each build task.

Creating Task Scripts Used in build.yml

  1. In the .cloudbuild directory, click Create and select Create File from the drop-down list. Name the file as build_job1.yml and add the following code to the file:

    version: 2.0
    steps:
      BUILD:
      - maven:
          image: cloudbuild@maven3.5.3-jdk8-open # The image is used for your build and can be customized.
          inputs:
            settings:
              public_repos:
                - https://mirrors.huawei.com/maven # Configure the dependency repository.
            cache: true # Determine whether to enable caching.
            command: mvn package -Dmaven.test.failure.ignore=true -U -e -X -B # The command to be run.

  2. Create build_job2.yml and build_job3.yml with the same code samples by following the instructions in 1.
  3. The following figure shows the directory that stores files of the code repository.

    Figure 1 Directory

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

    Table 2 Basic information

    Parameter

    Description

    Name

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

    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 and select the Maven template. Click OK. The Build Actions page is displayed.
  4. Click the Code tab. The build scripts in the Repo01 code repository will be loaded automatically.
  5. Click Save and Run. In the displayed dialog box, click Confirm. The build task run page is displayed.

Viewing the Build Results

The Build Processes tab page shows the complete flowchart of the current build tasks. While the build tasks are still running, you can see that Job1 and Job2 are running in parallel, and Job3 only runs after Job1 and Job2 are finished.

  1. On the Build Processes tab page, click either the Job1 node in the left-hand menu or the green Job1 rectangle in the right pane. The run details page of Job1 is displayed, where you can view the build logs of Job1, as shown in Figure 2.

    Figure 2 Viewing the build results

    The details page includes the following tabs:

    • The Actions tab shows the resource scheduling information and sequential position of this task within the whole build process.
    • The Build Parameters tab shows the global parameters of the current build task.
    • The Build Scripts tab shows the script run for the current build task.

  2. You can view the run details of Job2 and Job3 by following instructions in 1.

Kami menggunakan cookie untuk meningkatkan kualitas situs kami dan pengalaman Anda. Dengan melanjutkan penelusuran di situs kami berarti Anda menerima kebijakan cookie kami. Cari tahu selengkapnya

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback