Integrate Jenkins with GitLab to automatically build and deploy your Enterprise Distributed Application Service (EDAS) applications. When you push code to GitLab, a webhook triggers Jenkins to pull the code, run a Maven build, and deploy to EDAS through the toolkit-maven-plugin plug-in.
This workflow supports applications deployed on both Elastic Compute Service (ECS) clusters and Kubernetes clusters.
How it works
Code push to GitLab -> GitLab webhook triggers Jenkins -> Maven builds the project -> toolkit-maven-plugin deploys to EDASYou push code to your GitLab repository.
A GitLab webhook notifies Jenkins of the change.
Jenkins pulls the latest code and runs a Maven build.
The
toolkit-maven-pluginplug-in calls the EDAS POP API script to deploy the updated application.
Prerequisites
Before you begin, make sure that you have:
An Alibaba Cloud account with an AccessKey ID and AccessKey secret from the account you used to activate EDAS. Log on to the Alibaba Cloud console to create one if needed
An application created and deployed in the EDAS console. For instructions, see Create and deploy applications on ECS clusters and Create and deploy applications on Kubernetes clusters
The application ID from the Basic Information tab in Applications in the left-side navigation pane of the EDAS console
A self-managed GitLab instance or Alibaba Cloud Code for source code hosting
A working Jenkins installation
Maven installed on the build server
Configure the Maven project
Add the toolkit-maven-plugin plug-in to your project's pom.xml to define EDAS deployment settings. For the full plug-in configuration, see Use the toolkit-maven-plugin plug-in to update an application deployed in an ECS cluster.
After you configure the plug-in, we recommend that you use Maven on a self-managed server to verify whether the configuration is valid:
mvn clean package toolkit:deployA successful build and deployment confirms that your Maven project is ready for Jenkins automation.
Install Jenkins plug-ins
In the Jenkins console, go to System Management > Plugins.
Install the following plug-ins:
Plug-in Purpose git client plugin, git plugin Pull source code from a Git repository GitLab hook plug-in Trigger Jenkins builds through GitLab webhooks
Configure Maven in Jenkins
In the Jenkins console, go to Manage Jenkins > Global Tool Configuration.
Select your Maven version and configure the installation path.
Set up SSH authentication between Jenkins and GitLab
Generate an SSH key pair on the Jenkins server and add the public key to GitLab. This allows Jenkins to pull code without manual authentication.
On the Jenkins server, generate an SSH RSA key pair for the user that runs Jenkins. For details, see the GitLab SSH documentation.
In GitLab, go to Settings > Deploy Keys.
Click New Deploy Key and paste the public key from the Jenkins server.
Create a Jenkins job
On the Jenkins homepage, click New Item, enter a job name, and select Freestyle Project.
Under the Source Code Management tab, select Git and configure the following parameters:
Parameter Description Repository URL The Git repository URL for your project Credentials Select None if the SSH RSA key pair of the user that runs Jenkins has been added to GitLab of this Git project. Otherwise, an error is returned Under the Build Triggers tab, select Poll SCM.
Under the Build Environments tab, select Add Timestamps to the Console Output.
Under the Build tab, click Add Build Step and select Invoke Top-level Maven Targets.
Configure the Maven build step:
Parameter Value Maven Version Select the version you configured in Global Tool Configuration Goals clean package toolkit:deploy
Configure GitLab webhooks
Link GitLab to Jenkins so that each code push automatically triggers a build.
In your GitLab project, go to Setting > Web Hooks.
In the URL field, enter the webhook URL in the following format: Replace the placeholders with your actual values: Example:
Placeholder Description Example <jenkins-server>IP address or hostname of the Jenkins server 123.57.xx.xxx<port>Jenkins listening port 8080<git-repository-url>Git SSH URL of the project git@code.aliyun.com:tdy218/hello-edas.githttp://<jenkins-server>:<port>/git/notifyCommit?url=<git-repository-url>http://123.57.xx.xxx:8080/git/notifyCommit?url=git@code.aliyun.com:tdy218/hello-edas.gitClick Test Hook to verify the webhook connection.
Verify the deployment
After you complete the configuration, push a commit to your GitLab repository. The webhook triggers Jenkins, which runs Maven and deploys the application to EDAS.
To check the build result:
Go to the Jenkins job page and click Build Number > Console Output.
A successful deployment produces output similar to the following:
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: SUCCESSIf the deployment fails, log on to the EDAS console and click Applications in the left-side navigation pane. Click the name of your application. In the left-side navigation pane, click Change Records to view the deployment details and identify the failure cause.
Deploy a multi-module Maven project
For multi-module projects, the Jenkins job setup is the same as in Create a Jenkins job. The difference is that you need two Invoke Top-level Maven Targets build steps instead of one. Build the parent module first to resolve dependencies, then build and deploy the submodule.
Configure the two build steps as follows:
| Build step | Goals | Purpose |
|---|---|---|
| First | clean install | Build the parent module and resolve dependencies |
| Second | clean package toolkit:deploy | Build and deploy the target submodule |
Example: The following demo project has this structure:
edas-app-demo/ (parent module)
├── detail/ (submodule)
├── itemcenter/ (submodule)
└── itemcenter-api/ (submodule)To deploy the itemcenter submodule, run clean install on the parent module first, then run clean package toolkit:deploy on the itemcenter submodule.