Search code examples
jenkinsjenkins-pipelineartifactoryrollback

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!


Solution

  • 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:

    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.