feat: rollback support - ROLLBACK_TAG param se purani image par wapas jao
This commit is contained in:
parent
e7463b83f3
commit
fa00b7975c
11
Jenkinsfile
vendored
11
Jenkinsfile
vendored
@ -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',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user