Skip to content

Instantly share code, notes, and snippets.

@vpavlin
Last active May 12, 2017 03:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vpavlin/46a8869c872630aad2e188cf81ae64d3 to your computer and use it in GitHub Desktop.
Save vpavlin/46a8869c872630aad2e188cf81ae64d3 to your computer and use it in GitHub Desktop.
def appName="voting-app"
def project=""
def tag="blue"
def altTag="green"
def verbose="true"
node {
project = env.PROJECT_NAME
stage("Initialize") {
sh "oc get route ${appName} -n ${project} -o jsonpath='{ .spec.to.name }' --loglevel=4 > activeservice"
activeService = readFile('activeservice').trim()
if (activeService == "${appName}-blue") {
tag = "green"
altTag = "blue"
}
sh "oc get route ${tag}-${appName} -n ${project} -o jsonpath='{ .spec.host }' --loglevel=4 > routehost"
routeHost = readFile('routehost').trim()
}
stage("Build") {
echo "building tag ${tag}"
openshiftBuild buildConfig: appName, showBuildLogs: "true", verbose: verbose
}
stage("Deploy Test") {
openshiftTag srcStream: appName, srcTag: 'latest', destinationStream: appName, destinationTag: tag, verbose: verbose
openshiftVerifyDeployment deploymentConfig: "${appName}-${tag}", verbose: verbose
}
stage("Test") {
input message: "Test deployment: http://${routeHost}. Approve?", id: "approval"
}
stage("Go Live") {
sh "oc set -n ${project} route-backends ${appName} ${appName}-${tag}=100 ${appName}-${altTag}=0 --loglevel=4"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment