Created
September 2, 2019 03:43
-
-
Save giang-pham/2e029f7c998cdd279104c5758569c2d7 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
def switchToBlue() { | |
sh(returnStdout: true, script: "kubectl apply -f deploy/k8s/prod/switch/vs-blue.yaml") | |
} | |
def switchToGreen() { | |
sh(returnStdout: true, script: "kubectl apply -f deploy/k8s/prod/switch/vs-green.yaml") | |
} | |
pipeline { | |
agent any | |
stages { | |
stage("Switch") { | |
steps { | |
withKubeConfig([credentialsId: '[CREDENTIAL_ID]', serverUrl: '[AUTHENTICATION_SERVER]']) { | |
script { | |
active = sh(returnStdout: true, script: "kubectl get vs [VIRTUAL_SERVICE] -o yaml | grep -B1 'weight: 100' | pcregrep -o1 'subset: (.*)'").trim() | |
if (active == 'blue') { | |
switchToGreen() | |
} else { | |
switchToBlue() | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment