Skip to content

Commit

Permalink
Update v2
Browse files Browse the repository at this point in the history
  • Loading branch information
sidd-harth committed Jul 11, 2019
1 parent c4104f5 commit ef69e07
Show file tree
Hide file tree
Showing 62 changed files with 2,282 additions and 335 deletions.
166 changes: 94 additions & 72 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,79 +1,101 @@
node {
try {
notifySlack()
#!groovy

stage('Preparation') {
mvnHome = tool 'm2'
host = "https://assertible.com/deployments"
}
@Library('slackNotifications-shared-library@master') _

stage('Unit testing') {
sh "curl -u apikey: 'https://assertible.com/deployments' -d'{\"service\":\"d8d73-b0a94b325ae4\",\"environmentName\":\"production\",\"version\":\"v1\"}'"
}
stage('Policy-Code Analysis') {
// Run the maven build
env.NODEJS_HOME = "${tool 'nodejs'}"
env.PATH = "${env.NODEJS_HOME}/bin:${env.PATH}"
sh "npm -v"
sh "apigeelint -s /usr/lib/node_modules/npm/apigee-ci-deploy-bdd-lint-master/hr-api/apiproxy/ -f table.js"
}

stage('Promotion') {
timeout(time: 2, unit: 'DAYS') {
input 'Do you want to Approve?'
}
}
stage('Deploy to Production') {
// Run the maven build
sh "'${mvnHome}/bin/mvn' -f /usr/lib/node_modules/npm/apigee-ci-deploy-bdd-lint-master/hr-api/pom.xml install -Pprod -Dusername=<email_here> -Dpassword=<password_here>"
}
try {
stage('Integration Tests') {
// Run the maven build
env.NODEJS_HOME = "${tool 'nodejs'}"
env.PATH = "${env.NODEJS_HOME}/bin:${env.PATH}"
// Copy the features to npm directory in case of cucumber not found error
//sh "cp $WORKSPACE/hr-api/test/features/prod_tests.feature /usr/lib/node_modules/npm"
sh "cd /usr/lib/node_modules/npm && cucumber-js --format json:reports.json features/prod_tests.feature"
}
} catch (e) {
//if tests fail, I have used an shell script which has 3 APIs to undeploy, delete current revision & deploy previous revision
sh "$WORKSPACE/undeploy.sh"
throw e
} finally {
// generate cucumber reports in both Test Pass/Fail scenario
// to generate reports, cucumber plugin searches for an *.json file in Workspace by default
sh "cd /usr/lib/node_modules/npm && yes | cp -rf reports.json /var/lib/jenkins/workspace/apigee-devops"

}
} catch (e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
notifySlack(currentBuild.result)
}
}
pipeline {
agent any
tools {
maven 'M2'
jdk 'JDK'
nodejs 'NODEJS'
}

/*environment {
stable_revision_number = 9
}*/

stages {
stage('Initial-Checks') {
steps {
sendNotifications 'STARTED'
bat "npm -v"
bat "mvn -v"
echo "$apigeeUsername"
//echo "$stable_revision_number"
}
}
stage('Policy-Code Analysis') {
steps {
bat "npm install -g apigeelint"
bat "apigeelint -s HR-API/apiproxy/ -f codeframe.js"
}
}
stage('Unit-Test-With-Coverage') {
steps {
script {
try {
bat "npm install"
bat "npm test test/unit/*.js"
bat "npm run coverage test/unit/*.js"
} catch (e) {
throw e
} finally {
bat "cd coverage && cp cobertura-coverage.xml $WORKSPACE"
step([$class: 'CoberturaPublisher', coberturaReportFile: 'cobertura-coverage.xml'])
}
}
}
}
/*stage('Promotion') {
steps {
timeout(time: 2, unit: 'DAYS') {
input 'Do you want to Approve?'
}
}
}*/
stage('Deploy to Production') {
steps {
bat "sh && sh deploy.sh"
//bat "mvn -f HR-API/pom.xml install -Pprod -Dusername=${apigeeUsername} -Dpassword=${apigeePassword} -Dapigee.config.options=update"
}
}
stage('Integration Tests') {
steps {
script {
try {
// using credentials.sh to get the client_id and secret of the app..
// thought of using them in cucumber oauth feature
// bat "sh && sh credentials.sh"
bat "cd $WORKSPACE/test/integration && npm install"
bat "cd $WORKSPACE/test/integration && npm test"
} catch (e) {
//if tests fail, I have used an shell script which has 3 APIs to undeploy, delete current revision & deploy previous stable revision
bat "sh && sh undeploy.sh"
throw e
} finally {
// generate cucumber reports in both Test Pass/Fail scenario
bat "cd $WORKSPACE/test/integration && cp reports.json $WORKSPACE"
cucumber fileIncludePattern: 'reports.json'
build job: 'cucumber-report'
}
}
}
}
}

def notifySlack(String buildStatus = 'STARTED') {
// Build status of null means success.
cucumber '**/*.json'
buildStatus = buildStatus ? : 'SUCCESS'

def color

if (buildStatus == 'STARTED') {
color = '#636363'
} else if (buildStatus == 'SUCCESS') {
color = '#47ec05'
} else if (buildStatus == 'UNSTABLE') {
color = '#d5ee0d'
} else {
color = '#ec2805'
}
post {
always {
// cucumberSlackSend channel: 'apigee-cicd', json: '$WORKSPACE/reports.json'
sendNotifications currentBuild.result
}
}
}

def msg = "${buildStatus}: `${env.JOB_NAME}` #${env.BUILD_NUMBER}:\n${env.BUILD_URL}"
/*
slackSend(color: color, message: msg)
}
using shared library for slack reporting
the lib groovy script must be placed in a vars folder in SCM
using build job to call a Freestyle project which sends the Cucumber reports to slack
currently the cucumberSlackSend channel: 'apigee-cicd', json: '$WORKSPACE/reports.json'
option doesnt send the reports to Slack
*/
9 changes: 9 additions & 0 deletions credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
client_id=$(curl -H "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/onlineman477-eval/apiproducts/Cicd-Prod-Product?query=list&entity=keys")

id=$(jq -r .[0] <<< "${client_id}" )
echo $id

client_secret=$(curl -H "Authorization: Basic $base64encoded" "https://api.enterprise.apigee.com/v1/organizations/onlineman477-eval/developers/[email protected]/apps/hrapp/keys/$id")

secret=$(jq -r .consumerSecret <<< "${client_secret}" )
echo $secret
21 changes: 21 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#! /bin/bash

# this scripts checks for any new update on edge.json.
# if there is a update it is going to deploy both the config and proxy
# if there is NO update, only proxy will be deployed

# this script was written by Kurt Googler Kanaskie
# https://community.apigee.com/questions/70453/separating-proxy-and-config-deployment-using-maven.html

ConfigChanges=`git diff --name-only HEAD HEAD~1 | grep "edge.json"`
if [[ $? -eq 0 ]]
then
export EdgeConfigOptions="update"
else
export EdgeConfigOptions="none"
fi

# Redirect output from this script to an "edge.properties" file in Jenkins.
echo EdgeConfigOptions=$EdgeConfigOptions

mvn -f HR-API/pom.xml install -Pprod -Dusername=${apigeeUsername} -Dpassword=${apigeePassword} -Dapigee.config.options=$EdgeConfigOptions
29 changes: 22 additions & 7 deletions hr-api/apiproxy/hr-api.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<APIProxy revision="1" name="hr-api">
<APIProxy revision="15" name="HR-API">
<Basepaths>/hr</Basepaths>
<ConfigurationVersion majorVersion="4" minorVersion="0"/>
<CreatedAt>1525792835438</CreatedAt>
<CreatedAt>1562271590046</CreatedAt>
<CreatedBy>[email protected]</CreatedBy>
<Description></Description>
<Description>SILENTSHADOW$ git: e148adec SilentShadow</Description>
<DisplayName>hr-api</DisplayName>
<LastModifiedAt>1525864693839</LastModifiedAt>
<LastModifiedAt>1562687096831</LastModifiedAt>
<LastModifiedBy>[email protected]</LastModifiedBy>
<ManifestVersion>SHA-512:3a2c92ee2de43af8664bb78684297277f4009ba903192bfac059dc2e57d4c6b2dc46accaca487d8488f77b96c9470ab1ca4d51f5916054ba61f3909835a7561b</ManifestVersion>
<ManifestVersion>SHA-512:5a8b8e393941bd33f9de90bb8e2e959dd0af84369ee4247b06c9ccf814cda7c3a7a1fdab47e8f28e91e851894df59de30e0485f813b034ff05c3832210241939</ManifestVersion>
<Policies>
<Policy>AM-CustomErrorResponse</Policy>
<Policy>AM-PrivateKey</Policy>
<Policy>AM-Response</Policy>
<Policy>AM-Setting-New-Payload</Policy>
<Policy>AS-Remove-URIPath</Policy>
<Policy>Assign-Message-1</Policy>
<Policy>OAuth-v20-1</Policy>
<Policy>EV-Extracting-Payload</Policy>
<Policy>JS-Logging-User-Setting-ID</Policy>
<Policy>JTP-Too-Long-String</Policy>
<Policy>Key-Value-Map-Operations-Credentials</Policy>
<Policy>OAuth-Verify</Policy>
<Policy>REP-Checking-JSON-Payload</Policy>
<Policy>RF-Invalid-UserID</Policy>
<Policy>RF-Missing-Phone-Number</Policy>
<Policy>Response-Cache-CICD</Policy>
<Policy>Verify-JWT</Policy>
</Policies>
<ProxyEndpoints>
<ProxyEndpoint>default</ProxyEndpoint>
</ProxyEndpoints>
<Resources/>
<Resources>
<Resource>jsc://Logging-User-Setting-ID.js</Resource>
</Resources>
<Spec></Spec>
<TargetServers/>
<TargetEndpoints>
Expand Down
33 changes: 33 additions & 0 deletions hr-api/apiproxy/hr-api_rev31_2019_07_03.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<APIProxy revision="2" name="hr-api_rev31_2019_07_03">
<Basepaths>/hr</Basepaths>
<ConfigurationVersion majorVersion="4" minorVersion="0"/>
<CreatedAt>1562173347052</CreatedAt>
<CreatedBy>[email protected]</CreatedBy>
<Description>SILENTSHADOW$ git: e148adec SilentShadow</Description>
<DisplayName>hr-api</DisplayName>
<LastModifiedAt>1562173347052</LastModifiedAt>
<LastModifiedBy>[email protected]</LastModifiedBy>
<ManifestVersion>SHA-512:63957310ff6fbad21b6689d33034fddee98f6ab9b3839cb9e76d7d210e64759d5dc76f7ba6fe9365cd68b8006b19d57d29c5d627799b4e089a61618fbab2aac5</ManifestVersion>
<Policies>
<Policy>AM-Setting-New-Payload</Policy>
<Policy>AS-Remove-URIPath</Policy>
<Policy>Assign-Message-1</Policy>
<Policy>EV-Extracting-Payload</Policy>
<Policy>JS-Logging-User-Setting-ID</Policy>
<Policy>Key-Value-Map-Operations-Credentials</Policy>
<Policy>OAuth-Verify</Policy>
<Policy>Response-Cache-CICD</Policy>
</Policies>
<ProxyEndpoints>
<ProxyEndpoint>default</ProxyEndpoint>
</ProxyEndpoints>
<Resources>
<Resource>jsc://Logging-User-Setting-ID.js</Resource>
</Resources>
<Spec></Spec>
<TargetServers/>
<TargetEndpoints>
<TargetEndpoint>default</TargetEndpoint>
</TargetEndpoints>
</APIProxy>
27 changes: 21 additions & 6 deletions hr-api/apiproxy/manifests/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Manifest name="manifest">
<Policies>
<VersionInfo resourceName="AS-Remove-URIPath" version="SHA-512:fde74381181dd4d5a411a403db088aa097f8d090a9815bec653ed14a4fcfd30bcc656702cf0e403b54ce7968338ac8cc420fcee9c3895e1fcb5dad40fbb8b4e2"/>
<VersionInfo resourceName="Assign-Message-1" version="SHA-512:1f8a0d0956eee163855cb34e738ef9bb38950bf405908d08e7cc5d9a0e7455ee4226da2b686212d5c40b1128f8272cde49b60280d3d8e9c7bf56a056fc18bd43"/>
<VersionInfo resourceName="OAuth-v20-1" version="SHA-512:1b035c1b6ba93a87855ac5ba0e8d7f199a0128c754a0914849ce5e0b02338985011a6e46daeb4c150a2c43d7cd66a5c799ee3527d2c556670e34606bd7da791c"/>
<VersionInfo resourceName="AM-CustomErrorResponse" version="SHA-512:66cb0574d917d55505812e8d1b55c430e65650cdb84d7f29b7ce723b55e68d583179e7ee93ce935c353c446c564ce9e899d812282c59b5e1e538dca11b7e09c7"/>
<VersionInfo resourceName="AM-PrivateKey" version="SHA-512:4b99ae5d1dc289de4d7550ede7ea1407518de6154fc98a5d040edb74333793b4476531f7da70a7544e840c2647312b9de3518ffbe0ce1e3648818d7631bd5dee"/>
<VersionInfo resourceName="AM-Response" version="SHA-512:50ca5bd8c6c54d92ebc7fffbc4515575550f28511172a149126b5fa60b09bcdb9a70149a3aad34fbfa37fe00654fb9457a6cecaf3bdee5e61d3e3c57a384762f"/>
<VersionInfo resourceName="AM-Setting-New-Payload" version="SHA-512:b055acc12e4b42aea193d3cd52663d2e2d124f887cc977bf9bb7eae8cdda33905174110ab1d92e06e0bc540495fc7be638ac825fff895879b06125c7c6c49bd3"/>
<VersionInfo resourceName="AS-Remove-URIPath" version="SHA-512:ed87fcfe980a96b5ee22d6dc43780535088fcda4db077a7bf548cef714067304b31424bc69179284eec5cbdfba8b86d9a0652f86c26baec79ae15b06ed1088a2"/>
<VersionInfo resourceName="Assign-Message-1" version="SHA-512:bcdbcd358e53d0a1d1e1d32b1a5e7f0aba6e6a87f41b7596f887e21671235c7841fecc79458866a9a449d987350febae7327a3da844b4b79d5994d7d472f3da1"/>
<VersionInfo resourceName="EV-Extracting-Payload" version="SHA-512:a80cd2cfc4edf497cccbbe437c9665b825572134b99fc3ec89fb9e1f50640b2da47636bccd0b32e913840ada83cba6bab958d0b14e42df987257f68e11bb23ab"/>
<VersionInfo resourceName="JS-Logging-User-Setting-ID" version="SHA-512:6c9c95e659972777bfa136a71e44af683159034cf6c27c120c79330f65725d2f24d16aa00bdf243e54196be9c276162fc36289873e3ce57293018d3eada2afff"/>
<VersionInfo resourceName="JTP-Too-Long-String" version="SHA-512:1e428d0ffd9280ce7c93defdd107a10900866148cab470bc9d474d612c02792254b70eca2bb77e67e91bb90e4157309c65224f5138c2616f385358a9fb6b05b7"/>
<VersionInfo resourceName="Key-Value-Map-Operations-Credentials" version="SHA-512:d292a79ba31ddb8f583cae8c6b5c443e26d3bb623727176f75a12edf480f997346ab72e35c0650e6c2ba4ecd0bcfc0157058916df5957feb57465c044798bd60"/>
<VersionInfo resourceName="OAuth-Verify" version="SHA-512:33408b77457271a82e4f376e7ef711aba53cf768520fef6c0c2ef428d088e686809b52bba059222ad448db0757d71ba3315013f2aaa7964f6c8c3bdfd40f1283"/>
<VersionInfo resourceName="REP-Checking-JSON-Payload" version="SHA-512:748bfef1864a590a57a29174412225bf3b2981f734ca8955077a6947005315214de98cda550a3f053f89131e29402de311f4a7d4fb1e27f77fc3aa7db260f7e1"/>
<VersionInfo resourceName="RF-Invalid-UserID" version="SHA-512:54b0d07d04fef31b889d546c33d237e71602eacd9cb5fc4d17848e700e59164e6b7d378a7d1bb4cd62669b0c3251fd8393f6773c26b58ef611b441feb12e9280"/>
<VersionInfo resourceName="RF-Missing-Phone-Number" version="SHA-512:5d8f2e694beaf503d14dcaf32dce0b347b6a28baa480882507f62f87f579a108cae50011a8043f895089639977bed51b731d8094032f62daeca4d585092e5de7"/>
<VersionInfo resourceName="Response-Cache-CICD" version="SHA-512:c8727f9429d69fc0eee3296cdbaa607b6f77531816d815750d7fd78aebcb66935a170f4420a474693984566593090fc32fe80c7ef384c05cb877a44784f8b0aa"/>
<VersionInfo resourceName="Verify-JWT" version="SHA-512:40e6b5ea4e14efc30571dda7039dcd629c82788bf6f1dae6ac71af3e6eb04c3911db9915f9863d1be4be842f8fc40923303b6e4fd44f39690375288165e6d155"/>
</Policies>
<ProxyEndpoints>
<VersionInfo resourceName="default" version="SHA-512:af73ea2fa40951133f4d83bb33af0e93db53a20aa9417c232460e256d91f33ca45ddbd1a4b3c765c6c13fc04a80db6205381dd603bf08beea567afce96bb4971"/>
<VersionInfo resourceName="default" version="SHA-512:57b6baa7131d05a11051818a8ae1febec98b54107741a5ed3c89f8514c71c96c5e5fb6bd25cc3332566b69cf274439165e447a39daa11aeedc91f05586696a79"/>
</ProxyEndpoints>
<Resources/>
<Resources>
<VersionInfo resourceName="jsc://Logging-User-Setting-ID.js" version="SHA-512:374859a3702c920f97f5999c793ec6a5e664f7727ebd1c8ef7e5dfdc827c80b87d583c829b4c4bd7db421a25202ad1a7105902e7faf71fd50723be26dfec2e8f"/>
</Resources>
<SharedFlows/>
<TargetEndpoints>
<VersionInfo resourceName="default" version="SHA-512:0f452e4556ff1d1a94bcc2e36166e8cd8b47af92072a718944b222aba383cc019a566ae76fae6020bb03a225a9ba8851d7b79f29032c093dd4861a8e406b939e"/>
<VersionInfo resourceName="default" version="SHA-512:5697767967f504f54fb84d75aa0c8b37e133c4695a1a5ba04b399a4f2b29a7210965cd7d0371a8e67bb0b693c06e581cca69a09c4190ad3206c020d9228e5fed"/>
</TargetEndpoints>
</Manifest>
17 changes: 17 additions & 0 deletions hr-api/apiproxy/policies/AM-CustomErrorResponse.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-CustomErrorResponse">
<DisplayName>AM-CustomErrorResponse</DisplayName>
<Properties/>
<Set>
<Headers/>
<Payload contentType="application/json">
{
"error":"string length exceed more than 15 characters"
}
</Payload>
<StatusCode>400</StatusCode>
<ReasonPhrase>Bad Request</ReasonPhrase>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
13 changes: 13 additions & 0 deletions hr-api/apiproxy/policies/AM-PrivateKey.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-PrivateKey">
<DisplayName>AM-PrivateKey</DisplayName>
<Properties/>
<Properties/>
<AssignVariable>
<Name>private.key</Name>
<Value>cicd</Value>
<Ref/>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
14 changes: 14 additions & 0 deletions hr-api/apiproxy/policies/AM-Response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-Response">
<DisplayName>AM-Response</DisplayName>
<Properties/>
<Set>
<Payload contentType="application/json">
{
"msg":"Record deleted"
}
</Payload>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
Loading

0 comments on commit ef69e07

Please sign in to comment.