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

Building and Executing a Pipeline on Jenkins

Updated on 2025-01-03 GMT+08:00

Building a Pipeline

Build a pipeline in Jenkins to pull code from the code repository, pack the code into an image, and push the image to the SWR image repository.

  1. Click Dashboard in the upper left corner of the page to switch to the Jenkins Dashboard page. In the navigation pane on the right, click New Item.
  2. Enter an item name (for example, test-pipe) and select Pipeline.

    Figure 1 Pipeline

  3. Configure only the pipeline script and retain the default values for other parameters.

    The following pipeline script is for reference only. You can modify the script content based on your service requirements. For details about the syntax, see Pipeline.

    def swr_region = "cn-east-3"
    def organization = "container"
    def git_repo = "http://github.com/xxx.git"
    def app_git_branch = "master"
    
    
    podTemplate(
    inheritFrom: 'jenkins-agent',    // Replace the value with the name of the pod template created in 5.
    cloud: 'ap-test'    // Replace the value with the name of the cloud created in 4.
    ) {
       // Pull the code from the code repository.
       node(POD_LABEL) {
          stage('Pull the code.') {
                echo "pull clone"
                git branch: "${app_git_branch}",  url: "${git_repo}"
           }
    
       // Use the maven container to pack the code pulled from the code repository. (This packing method applies only to Java. Use another packing method for other languages.)
       container('maven'){
          stage ('Pack the code.') {
                echo "build package"
                sh "mvn clean package  -DskipTests"
           }
        }
    
       // Use the kaniko container to push the packed code to SWR and name the image tomcat.
       container('kaniko'){
          stage('Push the image.') {
                echo "build images and push  images"
                sh "/kaniko/executor -f Dockerfile -c . -d swr.${swr_region}.myhuaweicloud.com/${organization}/tomcat:${BUILD_ID} --force"
           }
        }      
    }
    }
    Table 1 Pipeline script parameters

    Parameter

    Example Value

    Description

    swr_region

    cn-east-3

    Region where the SWR image repository is located. For details, see Regions and Endpoints.

    NOTE:

    The SWR image repository is used to store images packaged by code. The region must be the same as that in 3.

    organization

    container

    Organization name in SWR. You can enter any organization name as needed.

    git_repo

    https://github.com/xxx.git

    Specific address where the code is stored, which is the address of the code library.

    app-git-branch

    master

    Branch of the code library.

  4. Click Save.

Executing the Pipeline and Viewing the Execution Result

After the pipeline is executed, a pod named pipe-xxx will be automatically created in the cluster, and three containers (named jnlp, kaniko, and maven) will be created in the pod based on the information in the pod template. The pod pulls code from the code repository, packs the code into an image, and pushes the image to the SWR image repository. After the operations are complete, the pod is automatically deleted.

  1. In the navigation pane, choose Build Now to execute the pipeline job.
  2. Return to the CCE console and click the cluster name. In the navigation pane, choose Workloads. On the Pods tab, view the pod created by the pipeline.

    Figure 2 Pod created by the pipeline

  3. Click More > View Container in the Operation column. You can see that three containers are created based on the pod template.

    Figure 3 Creating a container

  4. Verify that the pod has been deleted automatically. After the code is pulled from the code repository and packed into an image, and the image is pushed to the SWR image repository, the pod will be automatically deleted.

    Figure 4 Automatic pod deletion

  5. Log in to the SWR console and verify that the Tomcat image is available in the SWR image repository.

    Figure 5 Pushed image

Follow-up Operations: Releasing Resources

To avoid additional expenditures, release resources promptly if you no longer need them.

  1. Log in to the CCE console. In the navigation pane, choose Clusters.
  2. Locate the cluster, click in the upper right corner of the cluster card, and click Delete Cluster.
  3. In the displayed Delete Cluster dialog box, delete related resources as prompted.

    Enter DELETE and click Yes to start deleting the cluster.

    It takes 1 to 3 minutes to delete a cluster. If the cluster name disappears from the cluster list, the cluster has been deleted.

  4. Log in to the ECS console. In the navigation pane, choose Elastic Cloud Server. Locate the target ECS and click More > Delete.

    In the displayed dialog, select Delete the EIPs bound to the ECSs and Delete all data disks attached to the ECSs, and click Next.

    Figure 6 Deleting ECSs

    Enter DELETE and click OK to start deleting the ECS.

    It takes 0.5 minutes to 1 minute to delete an ECS. If the ECS name disappears from the ECS list, the ECS has been deleted.

    Figure 7 Confirming the deletion

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