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