Skip to content

Latest commit

 

History

History
119 lines (103 loc) · 7.46 KB

README.md

File metadata and controls

119 lines (103 loc) · 7.46 KB

CICD Demo - Apigee API Management Platform - v2

This repository includes the instructions and pipeline definition for CI/CD using Jenkins, Apigee Lint, Apickli, Cucumber Reports, Slack & Apigee Maven Deploy plugin on Apigee.

Often the most difficult and confusing aspect of application development is figuring out how to build a common framework for creating/deploying new applications. Over time, development teams have started using tools like Maven to automate some of these functions. This repository uses various tools/plugins for deploying Apigee bundles to the Edge platform.

Pipeline

Flow

Introduction

On every pipeline execution, the code goes through the following steps:

  1. Develop an API Proxy in test environment Apigee Edge UI, Download the proxy and push to Github.
  2. In Jenkins, Apigee Proxy bundle is cloned from Github.
  3. Code Analysis is done using Apigee Lint.
  4. Any Javascript files from apiproxy directory goes through Unit Tests done using mocha.
  5. Code coverage is done by Istanbul/nyc and reports are generated by Cobertura.
  6. Using edge.json configurations is created/updated and a new revision is published in prod environment using Apigee Maven Build Plugin.
  7. The newly deployed prod environment goes through Integration tests using Apickli.
  8. Apickli produced Cucumber Reports are displayed in Jenkins.
  9. If the test FAILS, current revision is undeployed and a stable revision is re-deployed.
  10. Build Success/Fail notification along with Cucumber reports are sent to Slack Room.

Prerequisites

Demo Guide

  1. HR API - A simple API to perform CRUD operations on employee records. For backend I am using Firestore DB.
  2. Download HR-API.zip proxy bundle from this repo/bundles & deploy to test env or create an sample API Proxy.
  3. Download CiCd-Security.zip proxy bundle from this repo/bundles & deploy to both prod & test environments.
  4. Fork this repo & create a directory structure as per HR-API directory & place your apiproxy folder.
  5. I am using an Parameterzied Build to pass the Apigee username, password and base64encoded string.
  6. ApigeeLint will go through the apiproxy folder,
apigeelint -s HR-API/apiproxy/ -f codeframe.js

Apigeelint

  1. Unit test any custom code within the proxy like Javascript in our case. But it can be NodeJS as well.
npm test test/unit/*.js
npm run coverage test/unit/*.js

Mocha

Istanbul

  1. Using Cobertura Plugin in try-catch-finally block to generate reports in Jenkins.
cd coverage && cp cobertura-coverage.xml $WORKSPACE
step([$class: 'CoberturaPublisher', coberturaReportFile: 'cobertura-coverage.xml'])

Cobertura

  1. Build & Deploy happens through Apigee Maven Plugin (update pom and edge.json files with appropiate details),
mvn -f HR-API/pom.xml install -Pprod -Dusername=${apigeeUsername} -Dpassword=${apigeePassword} -Dapigee.config.options=update

Maven

  1. Integration tests happen through Apickli - Cucumber - Gherkin Tests,
cd $WORKSPACE/test/integration && npm install
cd $WORKSPACE/test/integration && npm test
  1. Cucumber Reports plugin in Jenkins will use the reports.json file to create HTML Reports & statistics.

Cucumber-Reports

Cucumber-Reports

  1. If Integration tests fail, then through a undeploy.sh shell script I am undoing Step 9. Through Jenkins Environment variable I am getting the current deployed revision and storing it as Stable revision. Within Shell Script I am using this value to re-deploy in case of Failure.
curl -X DELETE --header "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/$org_name/environments/$env_name/apis/$api_name/revisions/$rev_num/deployments"
curl -X DELETE --header "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/$org_name/apis/$api_name/revisions/$rev_num"
curl -X POST --header "Content-Type: application/x-www-form-urlencoded" --header "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/$org_name/environments/$env_name/apis/$api_name/revisions/$stable_revision/deployments"
  1. To send cucumber-reports to Slack I used cucumber-slack-notifier, but the pipeline cmd is not working as expected/documented. So for the time being I am running a separate FreeStyle project >> Build >> Send Cucumber Report to Slack and point it to the reports.json in this pipeline directory.
build job: 'cucumber-report'
  1. When Build Starts/Ends & At any step if a Failure occurs, a notification is sent to Slack Room along with cucumber reports.

Slack

Things to do in upcoming versions

  1. Update Developer Portal.
    • After successful Integration Test, we can add another Stage to Update Developer Portal Docs.
    • Currently we have plugin/apis for updating Apigee Drupal based portal.
    • We do not have any APIs for updating Apigee Integrated Developer Portal as of 14th July 2019.
  2. Add Performace/Load Tests after Integrated Tests
  3. Use Git Branches/Projects for dev >> uat >> prod environments and use Jenkins to Merge and Commit updates.
  4. Use OAS and use Apigee Management APIs to create and deploy a proxy through Pipeline.

References

  1. Apigee - maven-jenkins-ci-demo

LICENSE

See the MIT LICENSE file.

Older Version - v1

v1