edit-icon download-icon

Build continuous integration

Last Updated: Oct 22, 2018

Using Jenkins, you can build a continuous integration scheme for EDAS applications. You need the skills for the following computer languages and development tools that are used in this solution:

Tool Description
Maven Maven is an automation tool for project management and build.
Jenkins Jenkins is a scalable continuous integration engine.
GitLab GitLab is an open-source application developed using Ruby on Rails. It provides a self-hosted Git repository, allowing you to access public or private projects from a web interface. Jusk like using GitHub, you can use it to browse source code, manage defects, and add annotations.

The procedure for building continuous integration is as follows:

Prerequisites

Complete the following tasks before you start continuous integration:

  1. Obtain Alibaba Cloud Access Key ID and Access Key Secret.

    1. Activate the EDAS service and use its Primary Account to log on to the Alibaba Cloud official website.

    2. Create an Access Key ID and Access Key Secret on Access Key Management console.

  2. Create an application in the EDAS Console.

    Before using Jenkins to automatically deploy an application, you must create an application that is ready for deployment in the EDAS Console.

    1. Log on to the EDAS console.

    2. Create an application. You can refer to Publish an application for details.

      Skip this step if you have already created an application.

    3. Select Application Management on the left-side menu bar. Click the name of the application you created in the previous step to go to the details page. There, copy and save the content in the “Application ID” field.

  3. Use GitLab to host your code.

    You can build a GitLab project on your own or use Alibaba Cloud Code.

    This article assumes that you have built your own GitLab. For more information about GitLab, see GitLab.

  4. Use Jenkins.

    Refer to Jenkins website for more information about Jenkins.

Install and configure Jenkins

  1. Follow instructions in Jenkins to install Jenkins.

    Skip this step if you have already installed Jenkins.

  2. Install the Python runtime environment on the Jenkins server (Python 2.7 or later only, but not Python 3).

    For Python installation instructions, refer to Python. If you have already installed Python, skip this step.

  3. In Jenkins, install the Git and GitLab plugins.

    On the menu bar of the Jenkins Console, choose System Management > Plugin Management to install the plugins.

    • Installing the GIT Client Plugin and GIT Plugin helps Jenkins pull code from the Git repository.

    • Installing the GitLab Hook Plugin helps Jenkins trigger application building after it receives a Hook from GitLab.

    Install Git and GitLab plugins

  4. Install JDK and Maven.

    On the menu bar of the Jenkins Console, choose System Management > System Settings.

  5. Generate an RSA key pair and import it to GitLab and Jenkins. They are used for the authentication of Jenkins in pulling code from the GitLab.

    1. Refer to the GitLab documentation for the generation of RSA key pairs.

    2. Go to your project’s GitLab homepage and on the menu bar, choose Settings > Deploy Keys. Then, click New Deploy Key to add and import a key.

    3. Add the RSA private key as a Jenkins credential.

      1. Click Credentials on the Jenkins homepage. Click Add credentials, enter required information on the right pane, and click OK.

      2. Select the SSH Username with private key authentication method.

        Enter Scope, Username, Private Key, and other configurations as follows. Copy the private key file of the RSA key pair generated in Step 1 to the “/var/jenkins_home/.ssh/id_rsa” file. You can enter the Scope, Username, and Private Key according to your actual situation.

  6. Create a Jenkins project.

    1. On the left of the Jenkins homepage, click New Item to create a Jenkins project.

    2. Set the Git repository URL, and select the credentials you created by using RSA in Step 5. After proper configuration, the screen will be as shown in the following figure. Selecting “Poll SCM” is required.

    3. Configure a Maven build and select Execute Shell for custom build(In this example, we call the Shell command for automated deployment after building. If your Jenkins is built on a Windows server, you must select Execute Windows batch command.)

      “python $WORKSPACE/build/build.py” configured in the preceding figure is a sample script provided by EDAS. This script primarily performs WAR package upload and application deployment. Detailed instructions are provided in steps 3 and 4 of the next section.

      Note: To deploy a Docker application use “python $WORKSPACE/build/dockerbuild.py” for the script “python $WORKSPACE/build/build.py”.

Configure GitLab Web hook for automated building

Click the GitLab project to go to the Settings page. Configure the project as shown in the following figure. Set “URL” to your Jenkins server address (for example, http://localhost:8080/).

After configuration, click Test Hook to perform a test.

Call EDAS API for deployment

  1. Download the demo project demo.zip.

  2. Copy the build directory in the demo to your Git repository.

  3. Open the .osscredentials file in the build directory and configure the Access Key ID and Access Key Secret obtained during preparation.

    Obtain AKSK

  4. The deployed applications can be classified into common ones and Docker ones, which use different open APIs and configuration methods.

    • Common applications

      Open the config.json file in the build directory and configure the WAR package address, application ID, and other attributes. The configuration file must be in JSON format.

      config.json

      The “host” attribute is the domain name or IP address you use to access the EDAS Console. If you are using EDAS on a public cloud, you do not have to change “host” and “port” for “edas”.

      In the “apps” attribute, you can configure one or more applications. The meaning of and ways to retrieve each attribute are as follows:

      • appName: The application name created during preparation. You can obtain it in the EDAS Console.
      • appId: The application ID created during preparation. You can obtain it in the EDAS Console.
      • userId: The user ID you use to log on to Alibaba Cloud.
      • target: The local path of the WAR package created after Maven compilation, and is a relative path with the Git project path as the root directory.
      • deployGroupId: The application group ID.
      • batch: Batch publishing.
    • Docker applications

      Docker applications can be deployed through WAR packages and images. With images, you only need to configure a Maven build and custom your build in Execute Shell for the Jenkins project, with the content “python $WORKSPACE/build/dockerbuild.py”.

      Open the dockerconfig.json file in the build directory and configure the WAR package address, application ID, and other attributes. The configuration file must be in JSON format.

      dockerconfig.json

      You can configure multiple applications in the “apps” attribute. The preceding figure configures two Docker applications, where the first is a WAR package and the second an image. The meaning of and ways to retrieve each attribute are as follows:

      • appName: The application name created during preparation. You can obtain it in the EDAS Console.
      • appId: The application ID created during preparation. You can obtain it in the EDAS Console.
      • userId: The user ID you use to log on to Alibaba Cloud.
      • type: The deployment type. The “upload” type is for WAR packages and “image” for images.
      • target: The local path of the WAR package created after Maven compilation. This attribute is required for WAR deployment.
      • imageUrl: The image URL. This attribute is required for image deployment.
      • packageVersion: The version number of the deployment package.
      • description: Information about the application.
      • deployToStr: The application group ID. When set to “all”, it indicates all application instances of this application.
      • regionId: The ID of the region where the application is located.
  5. After configuration, submit the changes to GitLab.

    After you commit the preceding configuration, a GitLab Hook is triggered. On receiving this Hook, Jenkins builds your Maven project and then calls the open API to trigger deployment.

    Note: For Docker image deployment, you can manually trigger the Jenkins project after configuration.

Thank you! We've received your feedback.