This topic shows you how to use Jenkins to build a project for continuous integration of applications in Enterprise Distributed Application Service (EDAS). Computer languages and development tools are used in the following examples. Before you get started with this topic, make sure that you are familiar with these languages and tools.
Obtain the AccessKey ID and AccessKey secret of your Alibaba Cloud account.
- Log on to the official Alibaba Cloud website by using your Alibaba Cloud account for which EDAS is activated.
- Before you use Jenkins to enable automatic deployment of applications, create and
deploy an application in the EDAS console.
- Log on to the EDAS console.
- Create and deploy an application. For more information, see Overview and Application hosting overview (applicable to Kubernetes clusters).
If you have created an application, skip this step.
- In the left-side navigation pane, click Applications. Click the name of the application that you create in the preceding step. On the application details page, obtain the application ID.
- Manage code on GitLab. You can build a GitLab project or use Alibaba Cloud Code.
In this topic, a self-managed GitLab project is used as an example. For more information about GitLab, see GitLab.
- Familiarize yourself with Jenkins. For more information about Jenkins, see Jenkins official website.
|Maven||Maven is a tool that enables the system to automatically build and manage projects.|
|Jenkins||Jenkins is a scalable engine for continuous integration.|
|GitLab||GitLab is an open source application developed by using Ruby on Rails. GitLab provides a self-managed Git repository that allows you to connect to a public or private project from a web page. GitLab enables similar features to GitHub. For example, you can view source code, and manage bugs and annotations on GitLab.|
Configure a project
Modify the configuration of your project. You can add toolkit-maven-plugin and deployment information. After you modify the project configuration, we recommend that you use Maven on your on-premises machine to check whether the configuration is valid.
Install and configure Jenkins
- Download Jenkins from the Jenkins official website and install it.
- In the left-side navigation pane of the Jenkins console, choose . Then, install the Git and GitLab plug-ins.
- The Git client plug-in and Git plug-in enable Jenkins to pull code from Git repositories.
- The GitLab Hook plug-in enables Jenkins to trigger project building after Jenkins receives a hook from GitLab.
- Install Maven. For more information, visit the Maven official website.
In the left-side navigation pane of the Jenkins console, choose, select the Maven version, and then configure the path.
- Create a Secure Shell (SSH) RSA key pair on the Jenkins server and import the public
key into GitLab. This provides automatic authentication for Jenkins when Jenkins pulls
code from GitLab.
- Create an SSH RSA key pair for a Jenkins user that is connected to the Jenkins server. For more information, see GitLab documentation.
- On the GitLab homepage, choose new deploy key. On the page that appears, import the SSH RSA public key that you create on the Jenkins server to add the key. and click
- Create a Jenkins job.
- In the left-side navigation pane of the Jenkins homepage, click New Item to create a Jenkins job and select Freestyle project.
- On the Source Code Management page, select Git and configure the parameters.
- Repository URL: the URL of the Git repository of your project.
- Credentials: the security credentials. Select None if the SSH RSA public key of the user that runs Jenkins has been added to your GitLab project. Otherwise, an error is returned.
- Click the Build Triggers tab and select Poll SCM.
- Click the Build Environments tab and select Add Timestamps to the Console Output.
- Click the Build tab and click Add Build Step.
- In the Invoke Top-level Maven Targets section, configure Maven Version and Goals. You can also deploy a multi-module project. For more information, see 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 clean package toolkit:deploy. If other parameters are available, configure the parameters as needed.
Configure GitLab web hooks to enable automatic building
- Right-click the GitLab project and choose Setting > Web Hooks.
- On the Web Hooks page, enter
http://Jenkins sever address:Listening port of the Jenkins server/git/notifyCommit?url=Git repository address of your projectin the URL field.
For example, you can enter
The Jenkins server address indicates the web address of your Jenkins server, as shown in the preceding figure. For example, you can specify
- Then, click Test Hook.
Commit the changes to GitLab
If the preceding configurations are valid, a GitLab hook is triggered. Jenkins builds your Maven project after Jenkins receives this hook. After your project is built, Jenkins calls the EDAS POP API script to trigger application deployment.
You can chooseto view the output log. The following log information shows that the application is deployed.
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 application fails to be deployed, log on to the EDAS console. In the left-side navigation pane, click Applications. On the Applications page, click the name of the application that you want to manage. The application details page appears. In the left-side navigation pane, click Change List to view the execution process of this deployment job.
Create a Jenkins job for a multi-module project
The operations for creating a Jenkins job for a multi-module project is the same as
those that are described in Step 5 in Install and configure Jenkins. You need to change only the Invoke Top-level Maven Targets configurations. Assume that your project is a multi-module project and you want to
deploy a submodule in Jenkins. In this case, run the
mvn clean install command in the parent module and run the
mvn clean package toolkit:deploy command in the submodule. The demo project uses the following structure:
In the demo project, detail, itemcenter, and itemcenter-api are submodules. Assume
that you want to deploy the itemcenter submodule. In this case, run the clean install
command in the parent module to build a target. Then, run the
clean package toolkit:deploy command in the itemcenter submodule to build a target.