All Products
Search
Document Center

Serverless App Engine:Use Jenkins to create a continuous integration for a Java application

Last Updated:Aug 27, 2025

This topic describes how to use Jenkins to build a continuous integration for a Java application in Serverless App Engine (SAE).

Prerequisites

Background information

You can use Jenkins to build continuous integration solutions for SAE applications. This topic is intended for developers who are familiar with the following languages or tools.

Tool

Description

Maven

Maven is an automation tool that is used to automatically build and manage projects.

Jenkins

Jenkins is a scalable automation server that facilitates continuous integration.

GitLab

GitLab is an open source, self-hosted software development platform that allows you to access private or public repositories on webpages. GitLab is built by using Ruby on Rails. Similar to GitHub, GitLab allows you to review code, manage defects, and leave comments.

Step 1: Configure the project

Modify the configurations of a Maven project, and add toolkit-maven-plugin and application deployment information. For more information, see Use a Maven plug-in to automatically deploy applications to SAE.

Note

After you configure the project, we recommend that you use Maven in a data center to verify whether the configuration is valid.

Step 2: Configure Jenkins

  1. In the Jenkins console, choose Manage Jenkins > Manage Plugins from the menu to install the Git and GitLab plug-ins.

    Note
    • The GIT Client plug-in and GIT plug-in fetch code from the Git repository.

    • The GitLab Hook plug-in enables GitLab webhooks to trigger a build on GitLab projects.

    Install and configure Jenkins

  2. In the Jenkins console, choose Manage Jenkins > Global Tool Configuration from the menu, configure the Maven version name and path, and then click Save.

     Configure Maven in the Jenkins console

  3. Generate an SSH RSA key pair on the Jenkins server and import the public key into GitLab. This enables automatic authentication of Jenkins when Jenkins fetches code from GitLab.

    1. Generate an SSH RSA key pair on the Jenkins server.

      Generate an SSH RSA key pair

    2. On the GitLab homepage, choose Settings > Deploy Keys. Click New Deploy Key to add a key, and import the SSH RSA public key you create on the Jenkins server.

      Use Jenkins to import a public key to GitLab

Step 3: Create a Jenkins project

  1. In the left-side navigation pane of the Jenkins homepage, click New Item. Enter an item name, select Freestyle project, and then click OK.

    Use Jenkins to create a project

  2. Click the Source Code Management tab. On the Source Code Management tab, select Git and set relevant parameters.

    • Repository URL: the URL of the Git repository of your project.

    • Credentials: The credentials. Select none.

      Important

      Make sure that your SSH RSA public key is added to the GitLab where the Git project resides. Otherwise, an error is reported.

  3. Click the Build Triggers tab. On the Build Triggers tab, select GitHub hook trigger for GITScm polling.

  4. Click the Build Environment tab. On the Build Environment tab, select Add Timestamps to the Console Output.

  5. Click the Build tab. On the Build tab, click Add build step and select Invoke top-level Maven targets from the drop-down list.

  6. Set Maven Version and Goals in the Invoke top-level Maven targets section. You can also deploy a multi-module project. For more information, see (Optional) Create a Jenkins job for a multi-module project.

    • Maven Version: Click the drop-down list next to this field and select the Maven Version you configured on the Global Tool Configuration page.

    • Goals: Enter mvn clean package toolkit:deploy -Dtoolkit_profile=toolkit_profile.yaml -Dtoolkit_package=toolkit_package.yaml -Dtoolkit_deploy=toolkit_deploy.yaml. You can configure more parameters based on your business requirements.

    SAE

    Note

    After you complete Maven configurations, you can use the SAE POP API to trigger application deployment in Step 5: Submit the changes to GitLab.

Step 4: Configure a GitLab webhook

  1. Right-click the GitLab project and choose Setting > Web Hooks.

  2. On the Web Hooks page, enter http://Jenkins sever address:Listening port of the Jenkins server/git/notifyCommit?url=Git repository address of your project in the URL field.

  3. Then, click Test Hook.

    Configuration result of the GitLab webhook

Step 5: Submit the changes to GitLab

If the preceding configurations are valid, a GitLab hook is triggered. After the hook is received, Jenkins builds your Maven project and then calls the SAE POP API and a script to trigger deployment.

Note

A script that is used to deploy the application with the SAE POP API is configured in the Maven project.

After the project is deployed, you can choose Build Number > Console Output to view the output logs.

15:58:51 [INFO] Deploy application successfully!
15:58:51 [INFO] ------------------------------------------------------------------------
15:58:51 [INFO] BUILD SUCCESS
15:58:51 [INFO] ------------------------------------------------------------------------
15:58:51 [INFO] Total time: 24.330 s
15:58:51 [INFO] Finished at: 2018-12-25T15:58:51+08:00
15:58:51 [INFO] Final Memory: 23M/443M
15:58:51 [INFO] ------------------------------------------------------------------------
15:58:51 Finished: SUCCESS
            

If the deployment fails, you can log on to the SAE console to view the deployment process. For more information, see View change records.

(Optional) Create a Jenkins job for a multi-module project

If you need to create a Jenkins job for a multi-module project, you can perform the following operations.

The procedure used to create a Jenkins job for a multi-module project is the same as Step 5. You only need to adjust the Invoke top-level Maven targets parameter. To deploy a submodule in Jenkins, you must run the mvn clean install command in the parent module and then call the mvn clean package toolkit:deploy -Dtoolkit_profile=toolkit_profile.yaml -Dtoolkit_package=toolkit_package.yaml -Dtoolkit_deploy=toolkit_deploy.yaml command in the submodule. For more information about the parameters, see Use a Maven plug-in to automatically deploy applications to SAE.

Structure of the sample project:

sh-3.2# tree -L 1 carshop
carshop
├── detail
├── itemcenter
├── itemcenter-api
└── pom.xml            

In the preceding structure, detail, itemcenter, and itemcenter-api modules are submodules. When you deploy the itemcenter submodule, you must set a clean install target in the parent module and then set clean package toolkit:deploy -Dtoolkit_profile=toolkit_profile.yaml -Dtoolkit_package=toolkit_package.yaml -Dtoolkit_deploy=toolkit_deploy.yaml target in the itemcenter submodule.

SAE