All Products
Search
Document Center

CloudOps Orchestration Service:Git deployment

Last Updated:Dec 15, 2025

Use this deployment type to publish an application whose source files are stored in a Git repository.

How it works

Important
  • If you deploy to an application group that is an Auto Scaling (ESS) group, scaling activities are paused during the deployment. They automatically resume after the deployment finishes, whether it succeeds or fails.

  • The deployment process follows a stop-then-start principle. Each deployment first runs the stop script and then runs the start script.

  1. Create and publish the deployment.

    Configure the application source file, start script, and stop script for the deployment.

    Create a release task, select a release mode, and publish the deployment to the target application group.

  2. Automated deployment process for the publishing task.

    1. Retrieve the deployment information. This includes the Git repository information and the application's start and stop scripts.

    2. Pull the code. The code is pulled from the specified branch into the code_deploy_application folder in the working directory.

    3. Run the stop script. The application stop script is run to stop the old version of the application.

    4. Run the start script. The application start script is run to start the new version of the application.

Scope

  • Deployments are supported only on Linux instances.

  • Only Shell scripts are supported for the start and stop scripts.

Procedure

  1. Create an application and import an Elastic Compute Service (ECS) instance.

    1. If you do not have an ECS instance, go to the ECS console - Custom Launch page. Create an ECS instance that runs a Linux operating system and has Internet access.

      Select an ECS image, such as Alibaba Cloud Linux 3.2104 LTS 64-bit or Ubuntu 22.04 64-bit. The scripts in the following examples are written for these two images. If you use a different image, you must modify the scripts based on the examples.
    2. Go to the ECS console - Application Management page, click Create from Existing Resources, create an application and an application group, and import the ECS instance into the application group.

  2. Create the deployment.

    1. Fork the following sample code to your personal Git repository.

      You must register a personal Gitee or GitHub account. If the instance is in the Chinese mainland, use Gitee.
    2. Go to the ECS console - Application Management page. On the My Applications tab, click the name of the target application.

    3. On the application product page, select the Deployment tab, and then click Create Deployment.

    4. On the Create Deployment page, set RevisionType to Git Repository Code, configure the parameters, and then click OK.

      • Git repository information: Configure the information for the Git repository where your code is located.

        If this is your first time, follow the prompts in the console to grant authorization for the Git repository.
      • Working directory: The directory where the application start and stop scripts are run. Example: /root/deploy. By default, the code is pulled to the code_deploy_application folder in this directory.

      • Application start script:

        Alibaba Cloud Linux

        ### Note: The code from the Git repository is automatically downloaded to the code_deploy_application folder in the working directory. The path is {working directory}/code_deploy_application.
        ### Start the current version of the application.
        function start_application() {
         cd ./code_deploy_application
         set -e
         yum install -y maven-3.5.4
         java -jar sample-spring-1.0-SNAPSHOT.jar &
        }
        
        start_application

        Ubuntu

        ### Note: The code from the Git repository is automatically downloaded to the code_deploy_application folder in the working directory. The path is {working directory}/code_deploy_application.
        ### Start the current version of the application.
        function start_application() {
         cd ./code_deploy_application
         set -e
         apt update
         apt install -y maven
         java -jar sample-spring-1.0-SNAPSHOT.jar &
        }
        
        start_application
      • Application stop script:

        ### Stop the application (if any)
        function stop_application() {
          PID=$(ps -ef | grep "sample-spring-1.0-SNAPSHOT.jar" | grep -v "grep" | awk '{print $2}')
          if [ -n "$PID" ]; then
            kill -9 $PID
          fi
        }
        
        stop_application
  3. Return to the deployment list. Find the deployment that you created and click Publish. Select the target group and click OK to start the deployment.

  4. Verify the result.

    1. Go to the details page of the target instance. Click Connect and select Workbench. Follow the prompts on the page to log on to the terminal.

    2. Run the curl http://localhost:8080/hello command. A return value of Alibaba Spring Sample! indicates that the deployment was successful.

Key parameters

Field

Description

Platform

Select the Git repository platform where the code is located.

Owner

Select the account that owns the Git repository. Grant authorization the first time you use it.

Organization

Select a personal repository or an organization repository.

Repository

Select the repository where the code is located.

Branch

Select the branch to deploy.

CommitId

You do not need to enter a value. After you select a branch, the system automatically obtains the latest CommitId.

Working directory

The working directory for the application's start and stop scripts.

  • Enter an absolute path.

  • The code is automatically pulled to the code_deploy_application folder in the working directory.

  • You can specify a directory that does not exist. It is created automatically during execution.

Application start script

The Shell script used to start the application.

Application stop script

The Shell script to stop the application.
The script must correctly stop the current and previous versions of the application. When no application is running, the script must also exit normally without errors.

For example, the following script stops a container named my-container. This script assumes that every version of the container has the same name. The script does not report an error if the container does not exist:

container_name="my-container"
container_id=$(docker ps -aq -f name=${container_name}) 
if [ -n "$container_id" ]; then
  docker rm -f $container_id
fi