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.
On every pipeline execution, the code goes through the following steps:
- Develop an API Proxy in
test
environment Apigee Edge UI, Download the proxy and push to Github. - In Jenkins, Apigee Proxy bundle is cloned from
Github
. - Code Analysis is done using
Apigee Lint
. - Any Javascript files from
apiproxy
directory goes throughUnit Tests
done usingmocha
. - Code coverage is done by
Istanbul/nyc
and reports are generated byCobertura
. - Using
edge.json
configurations is created/updated and a new revision is published inprod
environment usingApigee Maven Build Plugin
. - The newly deployed
prod
environment goes through Integration tests usingApickli
. - Apickli produced
Cucumber Reports
are displayed in Jenkins. - If the test
FAILS
, current revision isundeployed
and a stable revision isre-deployed
. - Build
Success/Fail
notification along withCucumber reports
are sent toSlack Room
.
- Apigee Edge Account
- Slack Account + Jenkins Config
- Cucumber-Slack-Notifier
- Cobertura Jenkins Plugin
- NodeJS & NPM
- Configure Jenkins with Git, Cucumber Reports, JDK, Maven, NodeJS, Slack Plugins
- HR API - A simple API to perform CRUD operations on employee records. For backend I am using Firestore DB.
- Download
HR-API.zip
proxy bundle from this repo/bundles & deploy totest
env or create an sample API Proxy. - Download
CiCd-Security.zip
proxy bundle from this repo/bundles & deploy to bothprod
&test
environments. - Fork this repo & create a directory structure as per
HR-API
directory & place yourapiproxy
folder. - I am using an Parameterzied Build to pass the Apigee
username
,password
andbase64encoded
string. ApigeeLint
will go through theapiproxy
folder,
apigeelint -s HR-API/apiproxy/ -f codeframe.js
- Unit test any custom code within the proxy like
Javascript
in our case. But it can beNodeJS
as well.
npm test test/unit/*.js
npm run coverage test/unit/*.js
- 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'])
- Build & Deploy happens through Apigee Maven Plugin (update
pom
andedge.json
files with appropiate details),
mvn -f HR-API/pom.xml install -Pprod -Dusername=${apigeeUsername} -Dpassword=${apigeePassword} -Dapigee.config.options=update
- Integration tests happen through Apickli - Cucumber - Gherkin Tests,
cd $WORKSPACE/test/integration && npm install
cd $WORKSPACE/test/integration && npm test
- Cucumber Reports plugin in Jenkins will use the
reports.json
file to create HTML Reports & statistics.
- 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 asStable 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"
- To send
cucumber-reports
toSlack
I used cucumber-slack-notifier, but the pipeline cmd is not working as expected/documented. So for the time being I am running a separateFreeStyle project >> Build >> Send Cucumber Report to Slack
and point it to the reports.json in this pipeline directory.
build job: 'cucumber-report'
- When Build Starts/Ends & At any step if a Failure occurs, a notification is sent to Slack Room along with cucumber reports.
- Update Developer Portal.
- After successful
Integration Test
, we can add another Stage toUpdate 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.
- After successful
- Add
Performace/Load Tests
afterIntegrated Tests
- Use Git Branches/Projects for
dev >> uat >> prod
environments and use Jenkins to Merge and Commit updates. - Use
OAS
and use Apigee Management APIs to create and deploy a proxy through Pipeline.
See the MIT LICENSE file.