Automating WSO2 Mediators Deployment with Jenkins, Nexus and Ansible

This article explains about an Automation process on how we can deploy custom mediators on to wso2 servers through a proper versioning and smooth deployment process which will reduce the cost of manual deployment.

Usually wso2 mediators build through maven, so here also I’m going to build the artifacts through maven and then push to the Nexus repository along with versioning mechanism and then we will use the Ansible to pull the artifact from the repository and install into wso2 servers.

To get explained this easily, below contents include in this article.

  1. Pipeline Implementation
  2. Ansible Script Implementation for Deployment
  3. Connecting the Pipeline -> Ansible
  4. Improvements
  5. References

1. Pipeline Implementation

for other environments it should build the release version of the artifacts and publish to the Nexus Repository.

Below Diagrams explains how we are going to implement this in a flow diagram.

Development Environment — SNAPSHOT Build, Publish and Deployment Process
Other Environment — Release Version Build, Publish and Deployment Process

1.1 Pre-Requisites

Nexus Artifact Uploader: This plugin to upload the artifact to Nexus Repository.

Maven Release Plug-in Plug-in: A plug-in that enables you to perform releases using the maven-release-plugin from Jenkins.

Pipeline Utility Steps: Utility steps for pipeline jobs.

Maven Integration plugin: This plug-in provides, for better and for worse, a deep integration of Jenkins and Maven.

SSH Pipeline Steps: SSH Pipeline Steps.

  • Ansible
  • Nexus Repository
  • Source Code Repository ( Here I’m using GitHub as my code repository )

1.2 Setting up Pipeline

1.2.1 SNAPSHOTS Build

We have created a folder, and now we can create the pipeline. Note that here we created a folder to include all the other mediators and group into one folder. If there is only one mediator then can go directly with the pipeline.

Copy the above and based on your configuration can modify and save it under pipeline script section pointed with arrow in the above Image.

Once you execute the build now option, the job will trigger the build and the built artifact will be published to Nexus Repository under maven-snapshots folder as below:

1.2.2 Release Build

  1. Creating a Tag using the current POM Version
  2. Committing the pom.xml with the next development version

So to create a release build pipeline, same as the previous steps create a folder mediator-releases and the create the pipeline with the name password-validator, then inside the pipeline script section copy the below groovy script. I have mentioned the parameter information as comments to understand easily.

Additional Step is to configure versioning for the release, this can be done using the below section.

Then you can copy the below content to the Pipeline script section.

Before executing the build need to update the below in the pom.xml of the specific code.

Need to add the below two tags:

And also create a settings.xml file and add it inside the project folder. The content of the settings.xml will be as below.

Now we are ready to execute the build and once the build ran successfully, then you can observe that the artifact published to maven-releases folder.

Note: If a particular git repository have multiple projects inside folders, you can provide the main git repository url and then can build specific projects inside the repository using the command mvn with providing -f option to set the specific pom.xml.

eg: mvn -f <folder-name>/pom.xml

2. Ansible Script Implementation for Deployment

Note: Before executing the ansible, the maven_artifact have a dependency with python-lxml. You need to installed it to the server where the particular deployment is happening.

The below task can be included as a task in a role and then it can be called during the ansible script execution.

And the usage of this Role can be invoked as below, this can be invoked inside a role or directly inside main task as below, here the <mediator_name> will be the mediator we are going to deploy and the values can be set as variables inside the inventories.

3. Connecting the Pipeline -> Ansible

4. Improvements

The maven_artifact in ansible having an issue when fetching the latest version of snapshot, so here when fetching the snapshots is happening based on provided snapshot version. This can be improved by finding a way to pull the latest. Note the Release fetch is happening properly and it can be fetched by providing version as “latest”.

5. References




Senior Tech Lead — Enterprise Integration | WSO2 Certified Solution Architect |