refactor: streamline Jenkinsfile by using helper methods for environment variables and agent labels #10
62
Jenkinsfile
vendored
62
Jenkinsfile
vendored
@ -1,35 +1,43 @@
|
|||||||
pipeline {
|
pipeline {
|
||||||
agent { label 'built-in' }
|
|
||||||
|
agent none
|
||||||
|
|
||||||
options {
|
options {
|
||||||
buildDiscarder(logRotator(numToKeepStr: '10'))
|
buildDiscarder(logRotator(numToKeepStr: '10'))
|
||||||
}
|
}
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
DEPLOY_PATH = "/var/www/bangararaju.kottedi.in/admin"
|
DEPLOY_PATH = getDeployPath()
|
||||||
|
ENV_FILE_ID = getEnvFileId()
|
||||||
|
TARGET_URL = getHealthUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
|
|
||||||
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(fileId: 'admin-uat-properties',
|
[configFile(
|
||||||
targetLocation: 'src/environments/environment.ts',
|
fileId: ENV_FILE_ID,
|
||||||
replaceTokens: true)]
|
targetLocation: 'src/environments/environment.ts',
|
||||||
|
replaceTokens: true
|
||||||
|
)]
|
||||||
) {
|
) {
|
||||||
echo "Environment file injected"
|
echo "Environment file injected for ${env.BRANCH_NAME}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Build Angular') {
|
stage('Build Angular') {
|
||||||
|
agent { label getAgentLabel() }
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
npm install
|
npm install
|
||||||
@ -39,6 +47,7 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Deploy') {
|
stage('Deploy') {
|
||||||
|
agent { label getAgentLabel() }
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh '''
|
||||||
rm -rf $DEPLOY_PATH/*
|
rm -rf $DEPLOY_PATH/*
|
||||||
@ -49,11 +58,12 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
stage('Health Check') {
|
stage('Health Check') {
|
||||||
|
agent { label getAgentLabel() }
|
||||||
steps {
|
steps {
|
||||||
sh '''
|
sh """
|
||||||
sleep 2
|
sleep 2
|
||||||
curl -f https://bangararaju-uat.kottedi.in/admin
|
curl -f ${TARGET_URL}
|
||||||
'''
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -67,3 +77,37 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------- Helper Methods --------
|
||||||
|
|
||||||
|
def getAgentLabel() {
|
||||||
|
if (env.BRANCH_NAME == 'prod') {
|
||||||
|
return 'oracle-node'
|
||||||
|
} else {
|
||||||
|
return 'built-in' // for develop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getEnvFileId() {
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getHealthUrl() {
|
||||||
|
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