All Products
Document Center

Build a Java application deliverable and publish it to ECS by using the canary release policy

Last Updated: Apr 01, 2021

1. Background

You can use this topic to assist your process automation under the following conditions: Code development in Java

  • Delivery in the JAR or WAR format

  • Execution on ECS or a self-managed host

  • Publication by using the canary release policy

2. Customer requirements

Customers use host deployment in the following typical scenarios:

  • Perform some quality checks on the source code such as unit testing and code scanning.

  • Build source code into a deliverable such as a JAR or WAR file.

  • Publish a deliverable to an ECS virtual host by using the canary release policy.

3. Apsara DevOps operations

The following example demonstrates how to build an application deliverable and publish it to ECS by using the canary release policy. A Java Spring Boot repository is used in the example.

Create a pipeline

1.Log on to Apsara DevOps Flow (

2.Click Create Pipeline.

image 1

3.Select the Java · Test, build Image, deploy to ECS/VM in Canary Deploy template and click Create.

image c

Configure a code repository

1.Add a code source. Select General Git. Set Code Repository to and Default Branch to master.You can enter any personal certificate, because a public code repository is used in the example.

image 2

Configure a build & archive task

1.Modify the Java Build & Archive task and add the Archive Path field. Set the value to file exists in the code repository and contains the script to boot applications on ECS. For subsequent host deployment, you must add the file to the package file. How to use the file will be described in the host deployment part.Here you specify two paths: target/and Flow packages and archives the two files (or folders) into an artifact. The artifact will also be used in the subsequent host deployment task.

image 3

Configure a first host group deployment task

1.Configure the host deployment task. Select Artifact Name.default from the drop-down list. The artifact is the artifact archived in the Java build & archive task.To configure a host group, you must click Create Deployment Group to create a host group first.

image 4

2.Click Create Service Authorization. You are redirected to RAM to complete RAM authorization. Then, you are automatically returned to Flow.Select the region and the ECS instance to be deployed. Click Next. Enter the host group name and click Save. The host group is created.The newly created host group is automatically added to the pipeline configurations.

image 5image 6image 7

3.Configure the deployment script.

  • Download Path: indicates where you store the compressed package created in the build & archive task. The value in this example is /home/admin/app/package.tgz.

  • Execute User: indicates which role executes the script? The value in this example is root.

  • Deployment Script: the content of the script. The value in this example:

mkdir -p /home/admin/application/ 
tar zxvf /home/admin/app/package.tgz -C /home/admin/application/ 
sh /home/admin/application/ restart
image 8

4.Configure a deployment policy

Suspend Strategy: indicates what suspension method is used in the host group, such as Suspend First Batch, Suspend Per Batch, or Without Suspension.We recommend that you select Suspend First Batch. After the first batch is published, check the online service. If no exceptions occur, you can continue publishing the remaining batches.

Batch Quantity: indicates the number of batches you want to divide the machines in the host group.For example, you divide a total of four machines into two batches. Each batch contains two machines.

Configure a manual approval task

1.Click Manual Approval and specify Validator.

image 9

Configure a second host group deployment task

1.Configure a second host group deployment task in the same way. Select the second host group to publish the application.

image 10

Run a pipeline

1.After the configurations are complete, click Save and Run to trigger the pipeline.

image 11image 12

2.Then, you can view the details of the pipeline, including code scan results, build logs, and deployment logs.

image 13

3.After the application is published on the host group, the pipeline is waiting for manual approval. You can verify the application.After you approve the publication, the application will be published on the second host groups.

image 14

4.If the manual approval fails, you can select the specific version you need to roll back in deployment history, and Flow will automatically roll back.12