develop #12
230
Jenkinsfile
vendored
230
Jenkinsfile
vendored
@ -1,102 +1,142 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
|
|
||||||
agent none
|
agent none
|
||||||
|
|
||||||
options {
|
options {
|
||||||
buildDiscarder(logRotator(numToKeepStr: '10'))
|
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||||
disableConcurrentBuilds()
|
disableConcurrentBuilds()
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
|
||||||
stage('Build') {
|
stage('Build & Test') {
|
||||||
agent { label getAgentLabel() }
|
agent { label getAgentLabel() }
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
|
||||||
stage('Cleanup Workspace') {
|
stage('Cleanup Workspace') {
|
||||||
steps {
|
steps {
|
||||||
cleanWs()
|
cleanWs()
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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') {
|
stage('Checkout') {
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
checkout scm
|
||||||
npm ci
|
}
|
||||||
ng build --configuration production --base-href /admin/
|
|
||||||
'''
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stage('Inject Environment File') {
|
||||||
|
when {
|
||||||
|
not {
|
||||||
|
anyOf {
|
||||||
|
branch pattern: "feature/.*", comparator: "REGEXP"
|
||||||
|
branch pattern: "bug/.*", comparator: "REGEXP"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
configFileProvider(
|
||||||
|
[configFile(
|
||||||
|
fileId: getEnvFileId(),
|
||||||
|
targetLocation: 'src/environments/environment.ts',
|
||||||
|
replaceTokens: true
|
||||||
|
)]
|
||||||
|
) {
|
||||||
|
echo "Injected environment for ${env.BRANCH_NAME}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Install Dependencies') {
|
||||||
|
steps {
|
||||||
|
sh 'npm ci'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Run Tests') {
|
||||||
|
when {
|
||||||
|
anyOf {
|
||||||
|
branch pattern: "feature/.*", comparator: "REGEXP"
|
||||||
|
branch pattern: "bug/.*", comparator: "REGEXP"
|
||||||
|
branch 'develop'
|
||||||
|
branch 'prod'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh 'npm run test -- --watch=false --browsers=ChromeHeadless'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stage('Build Angular App') {
|
||||||
|
when {
|
||||||
|
anyOf {
|
||||||
|
branch 'develop'
|
||||||
|
branch 'prod'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
sh '''
|
||||||
|
ng build --configuration production --base-href /admin/
|
||||||
|
'''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 🚨 Production Approval Gate
|
stage('Production Approval') {
|
||||||
stage('Production Approval') {
|
when {
|
||||||
when {
|
branch 'prod'
|
||||||
branch 'prod'
|
}
|
||||||
|
steps {
|
||||||
|
input message: "Approve deployment to PRODUCTION?", ok: "Deploy"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
steps {
|
|
||||||
input message: "Approve deployment to PRODUCTION?", ok: "Deploy"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stage('Deploy & Verify') {
|
stage('Deploy & Verify') {
|
||||||
agent { label getAgentLabel() }
|
|
||||||
|
|
||||||
stages {
|
when {
|
||||||
|
anyOf {
|
||||||
stage('Deploy') {
|
branch 'develop'
|
||||||
steps {
|
branch 'prod'
|
||||||
sh """
|
|
||||||
rsync -av --delete dist/portfolio-admin/browser/ ${getDeployPath()}/
|
|
||||||
sudo /usr/bin/systemctl reload nginx
|
|
||||||
"""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Health Check') {
|
agent { label getAgentLabel() }
|
||||||
steps {
|
|
||||||
sh """
|
|
||||||
sleep 3
|
|
||||||
curl -f ${getHealthUrl()}
|
|
||||||
"""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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 {
|
post {
|
||||||
success {
|
success {
|
||||||
echo "✅ Deployment successful for ${env.BRANCH_NAME}"
|
echo "Deployment successful for ${env.BRANCH_NAME}"
|
||||||
|
}
|
||||||
|
failure {
|
||||||
|
echo "Deployment failed for ${env.BRANCH_NAME}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
failure {
|
|
||||||
echo "❌ Deployment failed for ${env.BRANCH_NAME}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -104,33 +144,33 @@ post {
|
|||||||
//
|
//
|
||||||
|
|
||||||
def getAgentLabel() {
|
def getAgentLabel() {
|
||||||
if (env.BRANCH_NAME == 'prod') {
|
if (env.BRANCH_NAME == 'prod') {
|
||||||
return 'oracle-prod'
|
return 'oracle-prod'
|
||||||
} else {
|
} else {
|
||||||
return 'built-in'
|
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