หน้านี้ยังไม่พร้อมใช้งานในภาษาท้องถิ่นของคุณ เรากำลังพยายามอย่างหนักเพื่อเพิ่มเวอร์ชันภาษาอื่น ๆ เพิ่มเติม ขอบคุณสำหรับการสนับสนุนเสมอมา

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 Build Task on a Custom Environment (Built-in Executors, GUI)

Running a Build Task on a Custom Environment (Built-in Executors, GUI)

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

Scenario

You may need to extend CodeArts Build with custom environments in the following scenarios:

  • CodeArts Build uses Java 1.8 by default, but you may require Java 21.
  • Your build may require your enterprise's dedicated tools that are not supported by CodeArts Build.

In this practice, you customize a build environment to run a build task.

Requirements

  • You have created an organization named hwstaff_codeci_gray in SWR.
    • 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 CodeArts Repo Repository

Create the code file used for your build.

Creating an Image as the Custom Build Environment

Create an image as the custom environment.

Creating and Running a Build Task

Create, configure, and run a build task.

Viewing the Build Results

Check the build logs and result files to 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 displayed page, set Repository Name to custom_env_repo, and leave the other parameters as default. Click OK. The details page of the new code repository is displayed.
  5. In the root directory of the code repository, choose Create and select Create File from the drop-down list.

    Figure 1 Creating a file

  6. Name the file Dockerfile, copy the following code to the file, and click Submit.

    FROM ubuntu:latest
    
    # set maintainer
    LABEL maintainer=custom_image
    
    RUN apt-get update && apt-get install -y wget 
    
    RUN mkdir /usr/java && \
      cd /usr/java && \
      wget "https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz" && \
      tar -xvf jdk-17_linux-x64_bin.tar.gz && \
      rm -rf jdk-17_linux-x64_bin.tar.gz
    
    RUN mkdir /usr/maven && \
      cd /usr/maven && \
      wget "https://dlcdn.apache.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz" && \
      tar -xvf apache-maven-3.9.8-bin.tar.gz && \
      rm -rf apache-maven-3.9.8-bin.tar.gz
    
    ENV JAVA_HOME /usr/java/jdk-17.0.12
    ENV MAVEN_HOME /usr/maven/apache-maven-3.9.8
    ENV PATH $PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
    
    RUN java -version && mvn -v
    
    USER build
    Figure 2 Dockerfile content

    Dockerfile contains the following instructions for building a container image as your custom environment.

    Table 2 Dockerfile instructions

    Instruction

    Description

    FROM

    It specifies the base image (the latest official Ubuntu image is used in this practice) and must be the first instruction.

    LABEL

    It adds metadata to an image.

    RUN

    They are run when docker build creates an image. In this practice, RUN instructions install three tools: Wget, Java Development Kit (JDK) 17, and Maven 3.9.8. After environment variables are set, these instructions run commands to verify the installation of proper JDK and Maven versions.

    ENV

    They set environment variables. In this practice, ENV instructions set environment variables for JDK and Maven and add their directory to the PATH environment variable so that users can conveniently run JDK and Maven by invoking shortcut commands.

    USER

    It sets the user when the container is run. In this practice, the build user is set for the container runtime.

Creating an Image as the Custom Build Environment

  1. In the navigation pane, choose CICD > Build.
  2. Click Create Task. On the displayed Basic Information 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, custom_env_task.

    Code Source

    Select the code source from which code will be pulled for your build. In this practice, select Repo.

    Repository

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

    Default Branch

    Keep the default value master.

  3. Select Blank Template and click OK to create the build task. The Build Actions page is displayed.
  4. On the Build Actions page, click the GUI tab and click Add Build Actions.

    Figure 3 Adding a build action

  5. In the right pane, click the Container related tab. Hover over action Build Image and Push to SWR and click Add on the card. Set the parameters according to Figure 4. Expand the Organization drop-down list and select hwstaff_codeci_gray created to meet the requirements. Type custom_ubuntu_image in the Image Name text box, and v1.0 in Image Tag. Leave the other parameters as default.

    Figure 4 Configuring the build action

  6. Click Save and Run in the upper right corner. In the displayed dialog box, click Confirm. The build task run page is displayed.
  7. On the Actions tab, check that the console displays the logs of the build task as it runs. The Build Logs window automatically scrolls down to show new entries. As shown in Figure 5, the console prints logs of creating an image from the Dockerfile stored in the code repository.

    Figure 5 Build task run logs

  8. After the build task is successfully run, go to the SWR console. Choose My Images and click the Private Images tab (which is displayed by default). From there, click the name of the image (custom_ubuntu_image) created in 5 to access its details page.
  9. On the image details page, click Edit. In the displayed dialog box, set Type to Public and click OK.

    Figure 6 Image details

  10. In the Image Pull Command column, copy and save the complete image name following docker pull (swr.{regionID}.myhuaweicloud.com/hwstaff_codeci_gray/custom_ubuntu_image:v1.0 is copied in this practice) for future use. {regionID} indicates the ID of the current region.

    Figure 7 Complete image name

Creating and Running a Build Task

  1. Access CodeArts Build. 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, custom_env_build_task.
    • Code Source: Select the code source from which code will be pulled for this build. In this practice, select Repo.
    • Repository: Select custom_env_repo, the code repository created in Creating a CodeArts Repo Repository.

  2. Click Next. On the displayed page, select Blank Template. Click OK. The Build Actions page is displayed.
  3. On the Build Actions page, click the GUI tab and click Add Build Actions.
  4. In the right pane, click the Container related tab. Hover over action Use SWR Public Image and click Add on the card. Set the parameters according to Figure 4. In the Image Address text box, enter the complete image name swr.{regionID}.myhuaweicloud.com/hwstaff_codeci_gray/custom_ubuntu_image:v1.0 saved in 10. Copy the following sample code to the Commands window. Leave the other parameters as default.

    java -version # Show the JDK version contained in the current image.
    mvn -v    # Show the Maven version contained in the current image.
    mvn package -Dmaven.test.skip=true -U -e -X -B  # Run the maven build command.
    Figure 8 Configuring the action of using the SWR public image

  5. Click Add Action and add the Upload to Release Repo action. In the Package Location text box, enter **/target/*.?ar. Leave the other parameters as default.
  6. Click Save and Run in the upper right corner. In the displayed dialog box, click Confirm. The build task run page is displayed.

Viewing the Build Results

  1. After the build task is successfully run, go to the Actions tab page. On the top of the Build Logs window, click View More to scroll the window up and reveal the preceding logs. If you see Status: Downloaded newer image for swr.{regionID}.myhuaweicloud.com/hwstaff_codeci_gray/custom_ubuntu_image:v1.0 in the logs, the current build environment is created using the custom image.
  2. Click the Upload to Release Repo action on the left. The right-hand log window will display information about the upload of the build product to the release repo.
  3. In the navigation pane, choose Artifact > Release Repos.

    On the displayed page, find the folder that shares the same name as the build task, as shown in Figure 9. The software package can be found within this folder.
    Figure 9 Checking the software package

เราใช้คุกกี้เพื่อปรับปรุงไซต์และประสบการณ์การใช้ของคุณ การเรียกดูเว็บไซต์ของเราต่อแสดงว่าคุณยอมรับนโยบายคุกกี้ของเรา เรียนรู้เพิ่มเติม

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback