CICD your APIS with WSO2 APIM using Jenkins

Hasintha Indrajee
4 min readDec 1, 2019

An organization can have multiple environments with heterogeneous deployments patterns and configurations. These environments can have different APIs. WSO2 API Manager supports creating fully automated CI/CD pipelines for APIs and maintaining the lifecycle of API, changing environment-specific configurations throughout the CI/CD process.

In simple terms one of the main objectives of CICD in terms of API management is seamlessly migrating APIs across different environments reducing human intervene on the migration process.

With this post I am going to build a Jenkins pipeline which will push your APIs to multiple environments upon a Github hook. Wait.. why Github hook ? Well, that would be the central place of maintaining APIs where developers go and commit once APIs are exported from Dev environment.

We will be installing few things like NGrok and Jenkins in order to set this up in a local machine.

Install a Jenkins instance. Well I thought it’s a heavy process. But it’s very straight forward and very simple. Jenkins installation experience is very smooth and easy. On installation process itself, it will prompt you everything you need to do like setting up admin users. Once you install it you should be able to access it through browser localhost address.

Jenkins is running in localhost

NGrok is used to tunnel network traffic to your local machines localhost address through internet. In order to get a github hook on a commit we need to configure a jenkins endpoint which is publicly accessible to trigger the jenkins pipleline. Hence we will be exposing our locally installed Jenkins instance through NGrok so that it gets a publicly accessible address. Don’t worry installing NGork is the simplest thing in the world. Just download the binary and run a command.

Once installed just issue the below command. You have to be in the place where ngrok binary is located.

ngrok http 8080

This will route internet traffic to your local jenkins instance which is running on localhost 8080 port with http. Believe me this is super simple and amazing. worth trying.

Ngrok exposes localhost:8080 publicly

Now you can access your jenkins instance publicly using the given public address (or http address). Look at the address bar of the below image. Yes !!

Jenkins accessed from Ngrok public address.

Fine.. Done with Ngrok stuff. Let’s move on..

All the resources required for the rest of this project reside in Github repo If I briefly explain the content of this repo,

  1. There is an exported API SwaggerPetstore. This was created using WSO2 APIM 2.6.0 and exported using apimcli tool. Please refer [1] for more information about exporting and API. Once an API is exported it will be in .zip format. I have extracted it to add api_params.yaml file which contains environment specific parameters.
  2. The Jenkins pipeline is defined in the root level. With that pipeline, we will be adding different environments and then will be pushing artficats to each environment. I have two instances of APIM running in my local machine with port offsetted to 1 and 2.
  3. is a script which I am using in my jenkins pipleine to setup environments which will be used to push artifacts. Note that I have placed apimcli tool in /Users/Shared/Jenkins/Home/workspace/cicd/apimcli. This path is getting created when we create the jenkins pipeline with name cicd as described in below step. This apimcli tool has to have proper permission to be executed by jenkins user. (When you install jenkins a “jenkins” user is getting created and this user has to have exec rights to this tool).
owner of the apimcli is jenkins user

Create a pipeline using Jenkins.

Login to jenkins and go to New Item -> Pipeline. Give cicd as the name of the pipleine. Below are my jenkins pipeline configurations. I have to point to my existing pipeline file in github. That’s all what I did. Simple as that !!

Jenkins pipeline configurations.

Create a webhook in your github repo

Next step is to create a github webhook which will be triggered on a commit.

Go to settings of your cicd repo and configure a webhook. Please note that I have used admin:admin as the username and password for my jenkins instaces is admin. I have used the publicly accessible ngrok link to configure github webhook.

Configure github hook

Done. That’s it. Do a small change to the content of your repo and se whether your jenkins pipleline get’s triggered.

Build is triggered by Github hook and the pipeline is running

There you go !!!..