From fa00b7975c7cc18fc8b9dda7803a28cb3013f8fe Mon Sep 17 00:00:00 2001 From: devops Date: Wed, 16 Sep 2026 12:39:01 +0000 Subject: [PATCH] feat: rollback support - ROLLBACK_TAG param se purani image par wapas jao --- Jenkinsfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6fe2cb6..af8e16d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,10 +1,15 @@ pipeline { agent any + parameters { + string(name: 'ROLLBACK_TAG', defaultValue: '', + description: 'Khaali = normal build. Purana build number (jaise 2) = seedha us image par rollback, bina rebuild ke') + } + environment { REGISTRY = '51.195.4.170:5000' IMAGE_NAME = 'swim/demo-app' - IMAGE_TAG = "${env.BUILD_NUMBER}" + IMAGE_TAG = "${params.ROLLBACK_TAG?.trim() ? params.ROLLBACK_TAG : env.BUILD_NUMBER}" // Jenkins container ke andar workspace /var/jenkins_home/... hai, // par docker daemon HOST par chalta hai jahan wahi folder // /opt/devops/data/jenkins/... par hai. -v ke liye HOST ka path chahiye. @@ -27,6 +32,7 @@ pipeline { } stage('Test') { + when { expression { !params.ROLLBACK_TAG?.trim() } } steps { sh ''' # container ka path -> host ka path badlo @@ -43,6 +49,7 @@ pipeline { } stage('Build image') { + when { expression { !params.ROLLBACK_TAG?.trim() } } steps { sh ''' docker build \ @@ -55,6 +62,7 @@ pipeline { } stage('Smoke test image') { + when { expression { !params.ROLLBACK_TAG?.trim() } } steps { sh ''' CID=$(docker run -d -P ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}) @@ -71,6 +79,7 @@ assert r['version'] == '${IMAGE_TAG}', 'version galat!' } stage('Push to registry') { + when { expression { !params.ROLLBACK_TAG?.trim() } } steps { withCredentials([usernamePassword(credentialsId: 'registry-creds', usernameVariable: 'REG_USER',