Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jenkins rollback previous version of deploy

Here is the thing. I have some jenkins pipeline jobs in that deploy some java backend apps. The pipelines are run by scripts from SCM. This scripts are the ones that grab the development team code and: 1- checkout that code 2- compile and create WAR 3- copy war to web server.

Now developers want to implement a rollback and if a job is run, and a new deployment is done and faild, they want to go back to the last one that was working fine.

Is there a way to do this in jenkins and for example using Jfrog artifactory? we have artifactory configured and we can upload WARS (or other files) to that repo but is not being used. I don´t know how to implement this. I was thinking that using tags for different WAR files and if deployment failed, grabing from artifactory latest WAR that worked ok? Is this possible? how can this approach be done in jenkins using artifactory. I can implement a new step that after creating WAR, then it uploads that WAA to artifactory, but how I can then connect this with jenkins to use the WAR that I want? Any suggestion on how to do this? thank you!

like image 354
Chanafot Avatar asked Oct 09 '18 13:10

Chanafot


2 Answers

I suggest you these approaches:

Without Artifactory

In this case, you just need parametrize your current pipeline to receive branch name or tag as parameter.

Workflow could be:

  • Before merge your release branch to master , verify existence of tag with previous stable release or create a new one.
  • Merge your release (qa, test, or whatever) to master branch
  • Execute your current pipeline with master branch.
  • If some error is detected, perform a rollback using your SCM ( csv, svn, git, etc). For instance, bitbucket has a revert option in merged pull request section.
  • Execute again the same pipeline with master branch as parameter. If rollback was not possible, Execute this pipeline with last stable tag as parameter.

With Artifactory or some Artifact Repository

In this case, you need to adopt a software versioning strategy. Read this sources:

  • https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN400
  • https://stackoverflow.com/a/46967235/3957754

In the easiest mode, you just need to build an incremental release version of your wars. Spring versions works in a similar way :

spring-release-versions

https://mvnrepository.com/artifact/org.springframework/spring-core

For instance:

  • Today you have a 5.0.0-RELEASE stable version saved in your artifactory and deployed in production environments.
  • In the night, execute your pipeline and as final step upload your war api-5.0.0-RELEASE.war to your artifactory.
  • One month after, you have a new release version 5.0.1-RELEASE.
  • Execute your pipeline and if an error is detected, just download the previous stable version called 5.0.0-RELEASE and deploy it as rollback step.

Other similar techniques

  • Create a build of your application using docker and assigning an incremental version.
like image 124
JRichardsz Avatar answered Sep 28 '22 17:09

JRichardsz


As a replacement for Artifactory, you can use Github releases or Gitlab packages and follow a scenario such as (assuming a versioning scheme like prod.build_number.short_commit_hash) :

  1. Yesterday evening you released version prod.32.ehR456e
  2. Today it seems that this version is having issues in prod.
  3. Using an automated deployment pipeline, rollback by re-deploying version prod.31.fBr451e stored in github releases or gitlab packages.
like image 21
EddardOmeka Avatar answered Sep 28 '22 17:09

EddardOmeka