Skip to content

Instantly share code, notes, and snippets.

@giang-pham
Created September 2, 2019 03:43
Show Gist options
  • Save giang-pham/2e029f7c998cdd279104c5758569c2d7 to your computer and use it in GitHub Desktop.
Save giang-pham/2e029f7c998cdd279104c5758569c2d7 to your computer and use it in GitHub Desktop.
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