Skip to content

Instantly share code, notes, and snippets.

@jovemfelix
Created October 19, 2020 15:04
Show Gist options
  • Save jovemfelix/4eeb319b35cf8ed0689be29d8840fff2 to your computer and use it in GitHub Desktop.
Save jovemfelix/4eeb319b35cf8ed0689be29d8840fff2 to your computer and use it in GitHub Desktop.
Wait for Openshift Deploy
def waitDeploy(Map args) {
echos "[waitDeploy]: args ${args}"
if (!args.SLEEP) {
args.SLEEP = 10
}
if (!args.TIMEOUT) {
args.TIMEOUT = 10
}
openshift.withCluster() {
openshift.withProject("${args.OCP_NAMESPACE}") {
echos "Using project: ${openshift.project()} at ${args.PIPELINE_OCP_CONSOLE_URL}"
def dc = openshift.selector('dc', "${args.APP_NAME}").narrow("dc")
try {
timeout(time: args.TIMEOUT, unit: 'MINUTES') {
echos "[start verification of deploy] ${args.APP_NAME} ${dc}"
def latestDeploymentVersion
def pod
def podReady = false
def tentativas = 1
while (podReady == false) {
sleep(args.SLEEP)
try {
latestDeploymentVersion = dc.object().status.latestVersion
echos "latestDeploymentVersion: ${latestDeploymentVersion}"
pod = openshift.selector('pods', [deployment: "${args.APP_NAME}-${latestDeploymentVersion}"])
echos "Tentativa: ${tentativas} - Deploy: ${latestDeploymentVersion} - Pod: ${pod.object().metadata.name}\n"
if (args.PIPELINE_OCP_CONSOLE_URL) {
echos "LOG: ${args.PIPELINE_OCP_CONSOLE_URL}/project/${openshift.project()}/browse/pods/${pod.object().metadata.name}?tab=logs"
}
podReady = pod.object().status.containerStatuses[0].ready
} catch (exception) {
echos "[SKIP_ERROR] ${exception}"
podReady = false
} finally {
tentativas++
}
}
}
} catch (all) {
error "[deploy] O deploy no pode ser realizado. Verifique se existe healthcheck e veja os logs do pod."
}
// timeout(10) {
// def dc = openshift.selector('dc', "${args.APP_NAME}")
// dc.rollout().cancel()
// sleep(10)
// dc.rollout().latest()
// dc.rollout().status()
// }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment