Skip to content

Instantly share code, notes, and snippets.

@giang-pham
Last active September 2, 2019 03:33
Show Gist options
  • Save giang-pham/b124fe0b200f6df9464f070d10c56bf5 to your computer and use it in GitHub Desktop.
Save giang-pham/b124fe0b200f6df9464f070d10c56bf5 to your computer and use it in GitHub Desktop.
pipeline {
agent any
stages {
stage("Deploy") {
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()
echo "active: $active"
if (active == "blue") {
env.SUBSET = "green"
} else {
env.SUBSET = "blue"
}
echo "subset: ${env.SUBSET}"
echo "version: ${env.NEW_VERSION}"
sh(returnStdout: true, script: "SUBSET=${env.SUBSET} NEW_VERSION=${env.NEW_VERSION} envsubst < [DEPLOY_YAML_DIR]")
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment