This is the playground for setting up CI-CD pipeline with Jenkins and deploy on Pivotal Web Services
We are leveraging ngrok - secure introspectable tunnels to localhost to publish webhook events running on local jenkins.
Important Pieces for this Pipe-line
- Jenkins File
- Manifest File
pipeline {
agent any
stages {
stage('Build') {
steps {
withMaven(maven: 'my_maven_3.6.1') {
sh 'mvn clean package'
}
}
}
stage('Deploy') {
steps {
withCredentials([[$class : 'UsernamePasswordMultiBinding',
credentialsId : 'PIVOTAL_CLOUD_FOUNDRY',
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD']]) {
sh '/usr/local/bin/cf login -a http://api.run.pivotal.io -u $USERNAME -p $PASSWORD'
sh '/usr/local/bin/cf push'
}
}
}
}
}
---
applications:
- name: ci-cd-with-jenkins
instances: 1
memory: 800m
path: target/ci-cd-with-jenkins-0.0.1-SNAPSHOT.jar
- In order to do blue-green deployment, create 2 artifacts one with
ci-cd-blue
and anotherci-cd-green
Following Steps will deploy Blue/Green war file to Cloud Foundry
1) Login to Cloud Foundry ==> cf login
2) Check which apps are running ==> cf apps
3) Deploy app in cloud foundry ==> cf push -f manifest-blue.yml/manifest-green.yml
Let's map a generic route https://ci-cd-production.cfapps.io/version to these blue and green
cf map-route ci-cd-green cfapps.io --hostname ci-cd-production
cf map-route ci-cd-blue cfapps.io --hostname ci-cd-production
- Now both blue and green instance are being pointed out by
ci-cd-production
and since Cloud Foundry GO Router implements Software Load balancer and uses RoundRobin out of the box to distribute load. So we see output from blue and green interchangeably
Now since our Green features are good to go in production for all set of users, let's just remove blue mapping altogether from ci-cd-production route.
cf unmap-route ci-cd-blue cfapps.io --hostname ci-cd-production
Now production only points to green instance, We have successfully deployed new App version with No downtime required, using Blue-Green Deployment strategy.