feat: rollback support - ROLLBACK_TAG param se purani image par wapas jao

This commit is contained in:
devops 2026-09-16 12:39:01 +00:00
parent e7463b83f3
commit fa00b7975c

11
Jenkinsfile vendored
View File

@ -1,10 +1,15 @@
pipeline { pipeline {
agent any 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 { environment {
REGISTRY = '51.195.4.170:5000' REGISTRY = '51.195.4.170:5000'
IMAGE_NAME = 'swim/demo-app' 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, // Jenkins container ke andar workspace /var/jenkins_home/... hai,
// par docker daemon HOST par chalta hai jahan wahi folder // par docker daemon HOST par chalta hai jahan wahi folder
// /opt/devops/data/jenkins/... par hai. -v ke liye HOST ka path chahiye. // /opt/devops/data/jenkins/... par hai. -v ke liye HOST ka path chahiye.
@ -27,6 +32,7 @@ pipeline {
} }
stage('Test') { stage('Test') {
when { expression { !params.ROLLBACK_TAG?.trim() } }
steps { steps {
sh ''' sh '''
# container ka path -> host ka path badlo # container ka path -> host ka path badlo
@ -43,6 +49,7 @@ pipeline {
} }
stage('Build image') { stage('Build image') {
when { expression { !params.ROLLBACK_TAG?.trim() } }
steps { steps {
sh ''' sh '''
docker build \ docker build \
@ -55,6 +62,7 @@ pipeline {
} }
stage('Smoke test image') { stage('Smoke test image') {
when { expression { !params.ROLLBACK_TAG?.trim() } }
steps { steps {
sh ''' sh '''
CID=$(docker run -d -P ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}) 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') { stage('Push to registry') {
when { expression { !params.ROLLBACK_TAG?.trim() } }
steps { steps {
withCredentials([usernamePassword(credentialsId: 'registry-creds', withCredentials([usernamePassword(credentialsId: 'registry-creds',
usernameVariable: 'REG_USER', usernameVariable: 'REG_USER',