refactor: enhance Jenkinsfile structure and improve stage conditions for better clarity and maintainability
Some checks failed
bangararaju.kottedi.in/portfolio-admin/pipeline/head There was a failure building this commit
Some checks failed
bangararaju.kottedi.in/portfolio-admin/pipeline/head There was a failure building this commit
This commit is contained in:
parent
f33bf8cd01
commit
1eca714680
108
Jenkinsfile
vendored
108
Jenkinsfile
vendored
@ -1,15 +1,15 @@
|
||||
pipeline {
|
||||
|
||||
agent none
|
||||
agent none
|
||||
|
||||
options {
|
||||
options {
|
||||
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||
disableConcurrentBuilds()
|
||||
}
|
||||
}
|
||||
|
||||
stages {
|
||||
stages {
|
||||
|
||||
stage('Build') {
|
||||
stage('Build & Test') {
|
||||
agent { label getAgentLabel() }
|
||||
|
||||
stages {
|
||||
@ -27,6 +27,14 @@ stages {
|
||||
}
|
||||
|
||||
stage('Inject Environment File') {
|
||||
when {
|
||||
not {
|
||||
anyOf {
|
||||
branch pattern: "feature/.*", comparator: "REGEXP"
|
||||
branch pattern: "bug/.*", comparator: "REGEXP"
|
||||
}
|
||||
}
|
||||
}
|
||||
steps {
|
||||
configFileProvider(
|
||||
[configFile(
|
||||
@ -40,18 +48,43 @@ stages {
|
||||
}
|
||||
}
|
||||
|
||||
stage('Install & Build') {
|
||||
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 '''
|
||||
npm ci
|
||||
ng build --configuration production --base-href /admin/
|
||||
'''
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 🚨 Production Approval Gate
|
||||
stage('Production Approval') {
|
||||
when {
|
||||
branch 'prod'
|
||||
@ -62,6 +95,14 @@ stages {
|
||||
}
|
||||
|
||||
stage('Deploy & Verify') {
|
||||
|
||||
when {
|
||||
anyOf {
|
||||
branch 'develop'
|
||||
branch 'prod'
|
||||
}
|
||||
}
|
||||
|
||||
agent { label getAgentLabel() }
|
||||
|
||||
stages {
|
||||
@ -86,17 +127,16 @@ stages {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
post {
|
||||
post {
|
||||
success {
|
||||
echo "✅ Deployment successful for ${env.BRANCH_NAME}"
|
||||
echo "Deployment successful for ${env.BRANCH_NAME}"
|
||||
}
|
||||
failure {
|
||||
echo "❌ Deployment failed for ${env.BRANCH_NAME}"
|
||||
echo "Deployment failed for ${env.BRANCH_NAME}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
@ -104,33 +144,33 @@ post {
|
||||
//
|
||||
|
||||
def getAgentLabel() {
|
||||
if (env.BRANCH_NAME == 'prod') {
|
||||
return 'oracle-prod'
|
||||
} else {
|
||||
return 'built-in'
|
||||
}
|
||||
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