Pull code from a Git repository, build a software package, and upload it to Object Storage Service (OSS). This template is suitable for scenarios in which you want to build a software package and store it in OSS. The template supports building on an existing Elastic Compute Service (ECS) instance in your account or on a temporary instance that is released after the build.
Prerequisites
An ECS instance is created and has Internet access. For more information, see Create an ECS instance and Enable Internet access.
ImportantThis sample template supports only the Linux operating system.
OSS is activated and an OSS bucket is created. For more information, see Activate OSS and Create a bucket.
Sample template
You specify the code source, such as Object Storage Service (OSS) or Git. CloudOps Orchestration Service (OOS) generates a temporary URL to pull code from the specified source.
Build a software package such as a JAR package and upload it to OSS.
Example
Prepare the code source
This example uses a sample Spring Boot project. The code is available in Gitee and GitHub repositories. Before you start, fork the project to your own repository.
-
Gitee: Gitee sample code (Recommended for users in the Chinese mainland)
-
GitHub: GitHub sample code (Recommended for users outside the Chinese mainland)
Create a template
Log on to the CloudOps Orchestration Service console.
-
In the left-side navigation pane, choose , and then click Create Template.
Select Build a software package, upload it to OSS, and then deploy it and click Next Step.
On the Process Configuration tab, set the parameters and click Create Template.
Specify a code source to generate a temporary authorization link for pulling the code.
This example uses Gitee as the code source. Enter the Owner, Organization, repository, and branch for your repository.
NoteIf you have not authorized Alibaba Cloud to read your repositories from GitHub or Gitee, click Go to Authorization to grant access.
If you have already forked the sample code, your repositories are automatically listed in the repository drop-down list. Select the forked repository.
Build a software package such as a JAR package and upload it to OSS.
Select the code source and the ECS instance, and then provide the build command.
CodeResource: In this example,
gitis selected. The output of the previous task is used, which isauthorizedUrl.Choose Building Ecs: Select Existing ECS or New ECS as the build instance.
NoteIf you select New ECS, you are charged on a pay-as-you-go basis. OOS checks whether Docker is installed on the instance. If Docker is not installed, OOS installs Docker Community Edition automatically.
Build Configuration: Provide build commands as needed.
This topic provides only a sample build and deployment script. When you run the script, Maven is installed first and then a JAR package is created in the
targetdirectory. You can replace the sample script with one that suits your project.Sample script (Alibaba Cloud Linux 3)
### sample build script set -e yum install -y maven-3.5.4 mvn packageSample script (Ubuntu)
### sample build script set -e apt install -y maven mvn packageSample script (CentOS)
### sample build script set -e yum install -y maven mvn package
Provide the package path and the build name, which is the name of the package to be created.
In this example, the package path is
target/. OOS compresses the package into a.tgzfile.
Upload the build output to OSS.
Specify the OSS bucket and object path for the software package.
Click Create Template.
Execute the template
-
Log on to the CloudOps Orchestration Service console.
-
In the left-side navigation pane, choose .
-
On the custom task template page, find the template that you created and click Create an execution in the Actions column.
-
In the Basic Information step, configure the parameters and click Next: Set Parameters.
-
In the Parameter Settings step, if no changes are needed, click Next: Confirm.
Click Create.
On the task execution management page, a status of Successful indicates that the execution is complete.
Log on to the OSS console. Find the specified bucket and path to view the uploaded software package.
What to do next
When your code is updated, push it to the corresponding Git repository and run the template again. OOS pulls the latest code, builds the package again, and uploads it to OSS. You can also modify the template before running it.