CI/CD For API Development [WSO2 API Manager 2.6.0]
Lean how to use the plugin in your Maven Based projects to achieve the CI/CD.
Join the DZone community and get the full member experience.Join For Free
WSO2 API Manager is a complete platform for lifecycle management of APIs. Although the API Manager comes with a built-in module to publish APIs, it's not possible to apply CI/CD. To compensate this the API Manager provides a set of useful REST APIs and by using these APIs a CI/CD pipeline can be built easily.
I have created a Maven Plugin using the exposed REST APIs and in this article, I will be showing how to use the plugin in your Maven Based projects to achieve the CI/CD. Please feel free to download/clone the plugin and modify it according to your needs.
The plugin is created using the REST APIs exposed by WSO2 API Manager 2.6.0. So, to execute the CI/CD demo in the below section, you must have WSO2 API Manager 2.6.0 up and running.
We are implementing an API in a Java project (Maven based). When the implementation is done, we push the code to the Github. We define a pipeline in Jenkins server where we configure our Maven plugin to execute. On successful execution of the plugin, the API of our project (swagger.yaml) is published in the WSO2 API Manager (2.6.0).
Create a Simple Project
The complete source code of the API implementing project i.e blog-api can be found here.
Here is a snapshot of the pom.xml:
Note that in the pluginRepository I am pointing it to a public bitbucket repository for this demo. Feel free to clone/download the Plugin and install in your local repository. The plugin configuration is quite straightforward.
Download Jenkins and run it. Download the Maven Integration plugin and then configure it under
Jenkins -> Global Tool Configuration.
Create a Pipeline Project
Click New Item and create a Pipeline project.
Set the Build Trigger to every minute as shown below,
Here is a simple three staged pipeline definition.
Check details of how to use the Maven Plugin in the plugin documentation.
Commit and push changes of the blog-api project to Github. The Jenkins is polling on the GitHub repository every minute and the pipeline will be executed automatically. After successful execution of the pipeline, the API configured in the plugin will be published in the API Manager. (Make sure that the API Manager is running)
In this article, I have shown how easily the REST APIs of the WSO2 API Manager can be used to build a CI/CD pipeline. The plugin is very simple (for demo purpose), but feel free to make changes to it to adapt to your requirements.
Opinions expressed by DZone contributors are their own.