Created
May 29, 2018 10:01
-
-
Save cmcornejocrespo/835730f45b667cd6fadb8f9aca456e51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
timeout(time: 20, unit: 'MINUTES') { | |
def appName="dpro" | |
def project="pro-ja" | |
def tag="blue" | |
def altTag="green" | |
def verbose="false" | |
def app="polaris" | |
def version, mvnCmd = "mvn -s configuration/cicd-settings-nexus3.xml" | |
node { | |
stage('Build App') { | |
git branch: 'master', url: 'http://gogs:3000/gogs/polaris.git' | |
script { | |
def pom = readMavenPom file: 'pom.xml' | |
version = pom.version | |
} | |
sh "${mvnCmd} install -DskipTests=true" | |
} | |
stage('Test') { | |
sh "${mvnCmd} test" | |
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml']) | |
} | |
stage('Code Analysis') { | |
script { | |
sh "${mvnCmd} sonar:sonar -Dsonar.host.url=http://sonarqube:9000 -DskipTests=true" | |
} | |
} | |
stage('Archive App') { | |
sh "${mvnCmd} deploy -DskipTests=true -P nexus3" | |
} | |
stage("Build Image") { | |
echo "building image ${app}" | |
openshiftBuild buildConfig: app, showBuildLogs: "true", verbose: verbose, namespace: "dev" | |
} | |
stage("Deploy DEV") { | |
openshiftTag srcStream: app, srcTag: 'latest', destinationStream: app, destinationTag: tag, verbose: verbose, namespace: "dev" | |
openshiftVerifyDeployment deploymentConfig: "${app}-dc", verbose: verbose, namespace: "dev" | |
} | |
stage("Deploy STAGE") { | |
openshiftDeploy deploymentConfig: "pre-dc", verbose:verbose, namespace: "pre" | |
} | |
stage("Upload version artifact in PRO") { | |
input message: "Test deployment in PRO. Approve?", id: "approval" | |
} | |
stage("Initialize PRO") { | |
sh "oc get route ${appName} -n ${project} -o jsonpath='{ .spec.to.name }' --loglevel=4 > activeservice" | |
activeService = readFile('activeservice').trim() | |
if (activeService == "${project}-blue") { | |
tag = "green" | |
altTag = "blue" | |
} | |
sh "oc get route ${tag}-d${project} -n ${project} -o jsonpath='{ .spec.host }' --loglevel=4 > routehost" | |
routeHost = readFile('routehost').trim() | |
} | |
stage("Deploy Test PRO") { | |
openshiftTag srcStream: app, srcTag: 'latest', destinationStream: app, destinationTag: tag, verbose: verbose, namespace: "dev" | |
openshiftVerifyDeployment deploymentConfig: "${project}-${tag}", verbose: verbose, namespace: project | |
} | |
stage("Active deploy to ${tag}") { | |
input message: "Test deployment: http://${routeHost}. Approve?", id: "approval" | |
} | |
stage("Go Live") { | |
sh "oc set -n ${project} route-backends ${appName} ${project}-${tag}=100 ${project}-${altTag}=0 --loglevel=4" | |
} | |
} | |
} | |
} catch (err) { | |
echo "in catch block" | |
echo "Caught: ${err}" | |
currentBuild.result = 'FAILURE' | |
throw err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment