I switched from Deployment Configs to Deployments in Openshift 4. In my Jenkins pipelines I had a step for rolling out the DeploymentConfig which looked like this:
openshift.withCluster() {
openshift.withProject("project") {
def rm = openshift.selector("dc", app).rollout()
timeout(5) {
openshift.selector("dc", app).related('pods').untilEach(1) {
return (it.object().status.phase == "Running")
}
}
}
}
In the openshift-jenkins-plugin there doesn't seem to be an option to rollout a deployment. Deployment is also a native kubernetes object as far as I know opposed to the Openshift Object DeploymentConfig.
What would be an easy way to rollout a deployment in Openshift 4 in Jenkins?
CodePudding user response:
You can use the Kubectl with the Jenkin
kubectl rollout undo deployment/abc
you can use the kubectl
node {
stage('Apply Kubernetes files') {
withKubeConfig([credentialsId: 'user1', serverUrl: 'https://api.k8s.my-company.com']) {
sh 'kubectl apply -f my-kubernetes-directory'
}
}
}
You can rollout the deployment as per need using the command line and if you can make or pass the variables also.
https://jamesdefabia.github.io/docs/user-guide/kubectl/kubectl_rollout/
CodePudding user response:
Deployments do not natively have a rollout or redeploy option like DeploymentConfigs.
However, if you make a change in the Deployment yaml, a redeploy is done with the new configuration laid in. Using that idea, you can make a change in the Deployment's configuration that doesn't actually change your project and trigger that when you want a clean slate.
oc patch deployment/{Your Deployment name here} -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"last-restart\":\"`date '%s'`\"}}}}}"
That command makes an annotation named "last-restart" and sets a value of the current timestamp that you run it. If you run it again, it replaces the timestamp with an updated value. Both of these actions are a change enough to trigger a redeployment, but not a functional change to your project.