develop #11
183
Jenkinsfile
vendored
183
Jenkinsfile
vendored
@ -1,113 +1,136 @@
|
||||
pipeline {
|
||||
|
||||
agent none
|
||||
agent none
|
||||
|
||||
options {
|
||||
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||
}
|
||||
options {
|
||||
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||
disableConcurrentBuilds()
|
||||
}
|
||||
|
||||
environment {
|
||||
DEPLOY_PATH = getDeployPath()
|
||||
ENV_FILE_ID = getEnvFileId()
|
||||
TARGET_URL = getHealthUrl()
|
||||
}
|
||||
stages {
|
||||
|
||||
stages {
|
||||
stage('Build') {
|
||||
agent { label getAgentLabel() }
|
||||
|
||||
stage('Checkout') {
|
||||
agent { label getAgentLabel() }
|
||||
steps {
|
||||
checkout scm
|
||||
stages {
|
||||
|
||||
stage('Cleanup Workspace') {
|
||||
steps {
|
||||
cleanWs()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Inject Environment File') {
|
||||
agent { label getAgentLabel() }
|
||||
steps {
|
||||
configFileProvider(
|
||||
[configFile(
|
||||
fileId: ENV_FILE_ID,
|
||||
targetLocation: 'src/environments/environment.ts',
|
||||
replaceTokens: true
|
||||
)]
|
||||
) {
|
||||
echo "Environment file injected for ${env.BRANCH_NAME}"
|
||||
stage('Checkout') {
|
||||
steps {
|
||||
checkout scm
|
||||
}
|
||||
}
|
||||
|
||||
stage('Inject Environment File') {
|
||||
steps {
|
||||
configFileProvider(
|
||||
[configFile(
|
||||
fileId: getEnvFileId(),
|
||||
targetLocation: 'src/environments/environment.ts',
|
||||
replaceTokens: true
|
||||
)]
|
||||
) {
|
||||
echo "Injected environment for ${env.BRANCH_NAME}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install & Build') {
|
||||
steps {
|
||||
sh '''
|
||||
npm ci
|
||||
ng build --configuration production --base-href /admin/
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stage('Build Angular') {
|
||||
agent { label getAgentLabel() }
|
||||
steps {
|
||||
sh '''
|
||||
npm install
|
||||
ng build --configuration production --base-href /admin/
|
||||
'''
|
||||
}
|
||||
// 🚨 Production Approval Gate
|
||||
stage('Production Approval') {
|
||||
when {
|
||||
branch 'prod'
|
||||
}
|
||||
|
||||
stage('Deploy') {
|
||||
agent { label getAgentLabel() }
|
||||
steps {
|
||||
sh '''
|
||||
rm -rf $DEPLOY_PATH/*
|
||||
cp -r dist/portfolio-admin/browser/* $DEPLOY_PATH/
|
||||
sudo /usr/bin/systemctl reload nginx
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
stage('Health Check') {
|
||||
agent { label getAgentLabel() }
|
||||
steps {
|
||||
sh """
|
||||
sleep 2
|
||||
curl -f ${TARGET_URL}
|
||||
"""
|
||||
}
|
||||
steps {
|
||||
input message: "Approve deployment to PRODUCTION?", ok: "Deploy"
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
failure {
|
||||
echo "Deployment failed!"
|
||||
}
|
||||
success {
|
||||
echo "Deployment successful!"
|
||||
stage('Deploy & Verify') {
|
||||
agent { label getAgentLabel() }
|
||||
|
||||
stages {
|
||||
|
||||
stage('Deploy') {
|
||||
steps {
|
||||
sh """
|
||||
rsync -av --delete dist/portfolio-admin/browser/ ${getDeployPath()}/
|
||||
sudo /usr/bin/systemctl reload nginx
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('Health Check') {
|
||||
steps {
|
||||
sh """
|
||||
sleep 3
|
||||
curl -f ${getHealthUrl()}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
success {
|
||||
echo "✅ Deployment successful for ${env.BRANCH_NAME}"
|
||||
}
|
||||
failure {
|
||||
echo "❌ Deployment failed for ${env.BRANCH_NAME}"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// -------- Helper Methods --------
|
||||
//
|
||||
|
||||
def getAgentLabel() {
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return 'oracle-node'
|
||||
} else {
|
||||
return 'built-in' // for develop
|
||||
}
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return 'oracle-prod'
|
||||
} else {
|
||||
return 'built-in'
|
||||
}
|
||||
}
|
||||
|
||||
def getEnvFileId() {
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return 'admin-prod-properties'
|
||||
} else {
|
||||
return 'admin-uat-properties'
|
||||
}
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return 'admin-prod-properties'
|
||||
} else {
|
||||
return 'admin-uat-properties'
|
||||
}
|
||||
}
|
||||
|
||||
def getDeployPath() {
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return "/var/www/bangararaju.kottedi.in/admin"
|
||||
} else {
|
||||
return "/var/www/bangararaju.kottedi.in/admin"
|
||||
}
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return "/var/www/bangararaju.kottedi.in/admin"
|
||||
} else {
|
||||
return "/var/www/bangararaju.kottedi.in/admin"
|
||||
}
|
||||
}
|
||||
|
||||
def getHealthUrl() {
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return "https://bangararaju.kottedi.in/admin"
|
||||
} else {
|
||||
return "https://bangararaju-uat.kottedi.in/admin"
|
||||
}
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return "https://bangararaju.kottedi.in/admin"
|
||||
} else {
|
||||
return "https://bangararaju-uat.kottedi.in/admin"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user