Skip to main content
Skip table of contents

API Projects CICD with GIT and Jenkins

The continuous integration and continuous deployment (CI/CD) enables developers to deliver application changes frequently and reliably without error. Changes made to the applications in one environment can be automatically compiled and deployed to another environment in a seamless manner. 

  • CI establishes a consistent and automated way to build, package, and test applications.
  • CD picks up where CI ends by automating the delivery of applications to selected infrastructure environments.

The following guide explains how API projects created in the Development environment can be moved to production and deploy it automatically. For this CICD, we will be using GIT as source control and Jenkins to configure the CICD pipeline. We will be having a central Git repository which will store the API projects. Once the API projects are created in the dev environment, the user will commit the projects to the central git repository. Jenkins will detect the change in the GIT repository and execute the commands in the CICD pipeline to fetch the projects, save them in the production environment and deploy them.

Creating a central repository in Github

Open github using the URL www.github.com and click the New button on the left navigation panel to create a new repository In Github for the developer to push the flows from the development machine.

Provide an appropriate name for the repository in the Repository name text box and click the Create repository button.

The newly created repository can be seen on the left navigation panel.

Setting up the Jenkins Machine

Install the following on the Jenkins system:

  1. JENKINS
  2. GIT
  3. CURL

Configuring Jenkins

  1. Install HTTP Plugins on JENKINS dashboard (localhost:8080) and restart JENKINS server.
  2. Go to Jenkins Dashboard >> Manage Jenkins >> Global Tool Configuration.

    Here in Git section, provide the path to your git executable (C:\Program Files\Git\bin\git.exe)

  3. APPLY and then SAVE.

Creating a new Jenkins Job

To automate the deployment process, create a project in the Jenkins account.

  1. Open the Jenkins account and provide a name for the jenkins project and click OK.

     

  2. Click the General tab and add a description.

     

  3. Click the Source Code Management tab and provide the Repository URL under the Git option.

     

  4. Click the Build Triggers tab, select the Poll SCM option and specify a time interval (every minute or every hour) the Schedule text area.



  5. In the Build script choose the script type (Batch or Linux shell) and accordingly put the contents of the CI-CD script present in <FIORANO_HOME>/esb/samples/scripts. You may want to modify it according to your requirements. You can write a sample script of your own. Here is an example of a bash script:

    CODE
    cd /test_jenkins/fiorano-api/; git pull;
    cd /test_jenkins/fiorano-api/apiprojects/testgit/1.0/;
    zip -r testgit.zip *
    mv testgit.zip /test_jenkins/;
    cd /test_jenkins/;
    curl -X POST"http://192.168.2.134:1981/api/ams/apiprojects/testgit/1.0/Development"-H "accept: application/json" -H "api_key:x--IBwdzxcdgtfqAcmEwUsBi" -H "Content-Type: application/json" -d
    "{\"action\":\"UNDEPLOY\"}";
    curl -X POST
    "http://192.168.2.134:1981/api/ams/apiprojects/import?overwrite=true&rename=false"
    -H "accept: application/json" -H "api_key:
    x--IBwdzxcdgtfqAcmEwUsBi" -H "Content-Type: multipart/form-data"
    -F "file=@testgit.zip;type=application/zip";
    curl
    -X POST
    "http://192.168.2.134:1981/api/ams/apiprojects/testgit/1.0/Development"
    -H  "accept: application/json"
    -H  "api_key:
    x--IBwdzxcdgtfqAcmEwUsBi" -H 
    "Content-Type: application/json" -d
    "{\"action\":\"DEPLOY\"}"



  6. Configure other features like post build actions based on your requirements.

Configuring Git in Jenkins machine by creating a local Git repository

Clone github repository to the system in which Jenkins is installed by providing the path in the Jenkins pipeline shell script:

Clone the local apiproject repository with Github (/test_jenkins/fiorano-api/apiprojects/) using the command as below:

CODE
git clone https://github.com/xcloud/fiorano-api-git.git

Making changes in the local repository and deploying it to the central repository 

  1. Edit the apiproject in one of the following ways and save it:
    1. from the dashboard.
    2. change the apiproject by opening file /test_jenkins/fiorano-api/apiprojects/testgit/1.0/policies/bmp/Development.xml and edit the payload tag. 



  2. Commit the changes to the central repository.



  3. Push to apply the changes in the central repository.

Testing the deployment

To check if the change is automatically deployed, open the apiproject URL below in the browser:
http://192.168.2.134:1860/testgit/1.0/

Refresh after a minute/hour (as configured in Jenkins) if changes are not visible.

Jenkins Flow

  1. Detect any change in the GIT repository.
  2. Clone the repository in the workspace path specified in the script.
  3. Zip the directories (API Projects / Event Processes) inside it.
  4. Undeploy/ stop the API Projects / Event Processes if running.
  5. Import the zipped contents in step 3.
  6. Deploy/ start the API Projects / Event Processes.
  7. If any API Project / Event Process is deleted from the GIT repository, then after step 4, invoke the "delete call".

Build Script

  1. The script (CI-CD.bat and CI-CD.sh) are present inside <FIORANO_HOME>/esb/samples/scripts.
  2. Provide WORKSPACE_PATH, CURL_PATH, REPO_NAME and github link to be cloned till .git.
  3. Sample CI/CD scripts across all platforms are provided to automate the deployment of Event Processes. In order to do the same for APIProjects, simply provide the correct CURLs.
  4. The scripts are created and tested for Linux and Windows. In order to zip the contents in Windows, we are using Powershell Compress-Archive. You may change it accordingly.
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.