A Brief Introduction to Apigee CICD Pipeline

In this post, I am going to show you how to build a Jenkins CICD pipeline from scratch for testing and deploying an Apigee proxy. To be honest, this is not a detailed tutorial, I expect the users to know the basics of Apigee and Jenkins to understand the steps.

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 tutorial uses various tools/plugins for deploying Apigee Proxy bundles to the Apigee Edge platform.

The entire source code is available on Github, please feel free to fork it.

Pipeline Steps
Apigee CICD Pipeline

At a high level, 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 are 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, the 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:


Detailed Steps:

  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 a 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 a Parameterized Build in Jenkins Job 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

7. 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

8. 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'])

9. 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

10. Integration tests happen through Apickli — Cucumber — Gherkin Tests,

cd $WORKSPACE/test/integration && npm install
cd $WORKSPACE/test/integration && npm test

11. Cucumber Reports plugin in Jenkins will use the reports.json file to create HTML Reports & statistics.

12. If Integration tests fail, then through a undeploy.sh shell script I am undoing Step 9. Through Jenkins Environment variable I am getting the currently 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"

13. 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'

14. When Build Starts/Ends & At any step if a Failure occurs, a notification is sent to Slack Room along with cucumber reports.

We can add more steps to the Pipeline:

  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.

Also have a look at this repo for more info, Apigee — maven-jenkins-ci-demo

The entire source code is available on Github, please feel free to fork it.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade