How to rollback new version to older version through jenkins pipeline

Hi Team,
How to rollback new version to older version using jenkins pipeline, example I have deployed a war file or docker image but we want to rollback a week ago war file or docker image? What to do for that need to create another pipeline if yes how to create or is there anither way please provide me pipeline or steps. Thanks!

Usually, the answer is:

  1. Write a script that performs the desired operation
  2. Add that script to a source code repository
  3. Call that script from a very small Jenkinsfile in that source code repository

By creating the script independent of Jenkins, you assure that you can develop it, refine it, test it, and debug it from your desktop, without requiring any special from Jenkins.

When you run it in Jenkins, you’ll probably need to provide credentials to the script so that it can perform the necessary operations. The Jenkins Pipeline step withCredentials will help with that.

Hi MarkEWaite,
Could you please share the sample scripts and pipeline if you have, it would be very helpful for my work Thanks.

I don’t have sample rollback scripts to share. There are many sample Pipelines available in the Jenkins documentation, in various blog posts, and on many video tutorials.

I’m accustomed to Docker container content downgrades being performed by creating a new container image (incrementing a version number in the container label) while downgrading the component in the container definition.

Welcome to the community!
I don’t use pipelines; but I write shell scripts all the time:
In jenkins I initiate a bash script that accepts a parameter ROLLBACK. this is a ‘true’/‘false’ parameter (Checked or not checked).
There is a multi-line text block with normally contains the new container version tags.

.env-template is an environmental file that has all necessary variables EXCEPT the versions to be changed, denoted with <VERSION_TAGS> as a placeholder. This takes the text box into a temp file .ver, used for validation. This will copy the contents of .ver into .env-template creating an .env.tmp. Finally .env.tmp is copied to .env. Before changes were initiated a cope of .env was also created (rollback.env). From efficiency, there is a lot of copying; but my files are small so impact is minimal

In the event a rollback was initiated, the variable is checked in Jenkins; and the rollback.env from the previous (successful?) deployment was copied to .env.tmp to be copied in to .env per normal operation. if you have two or more unsuccessful scripts run in a row, then the rollback is lost. But that can be easily mitigated.

While this may not solve your question, it may point you in the right direction.


if [[ $ROLLBACK = true ]]; then
        echo "Rolling back to last deployment"
        cp rollback.env .env.tmp
        cp .env rollback.env
        # Replacing the build version value
        echo "Replacing the environment value in $ENV"
        echo $MULTI_LINE_VER | sed 's/ /\n/g'  > .ver
        sed -e '/<VERSION_TAGS>/r .ver' -e '/<VERSION_TAGS>/d' .env-template > .env.tmp

cp .env.tmp .env