Edit Jenkinsfile
This commit is contained in:
Vendored
+33
-70
@@ -2,7 +2,7 @@ pipeline {
|
|||||||
agent any
|
agent any
|
||||||
|
|
||||||
environment {
|
environment {
|
||||||
WORKSPACE_DIR = '/home/jenkins/prod/authz'
|
WORKSPACE_PROD_DIR = '/home/jenkins/prod/authz'
|
||||||
WORKSPACE_DEV_DIR = '/home/jenkins/dev/authz'
|
WORKSPACE_DEV_DIR = '/home/jenkins/dev/authz'
|
||||||
WORKSPACE_UAT_DIR = '/home/jenkins/uat/authz'
|
WORKSPACE_UAT_DIR = '/home/jenkins/uat/authz'
|
||||||
WORKSPACE_SQA_DIR = '/home/jenkins/sqa/authz'
|
WORKSPACE_SQA_DIR = '/home/jenkins/sqa/authz'
|
||||||
@@ -17,24 +17,20 @@ pipeline {
|
|||||||
def SCANNER_HOME = tool 'SonarScanner'
|
def SCANNER_HOME = tool 'SonarScanner'
|
||||||
|
|
||||||
stage('SonarQube Analysis') {
|
stage('SonarQube Analysis') {
|
||||||
|
|
||||||
withSonarQubeEnv('SonarQube') {
|
withSonarQubeEnv('SonarQube') {
|
||||||
sh "${SCANNER_HOME}/bin/sonar-scanner"
|
sh "${SCANNER_HOME}/bin/sonar-scanner"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Quality Gate') {
|
stage('Quality Gate') {
|
||||||
|
|
||||||
script {
|
script {
|
||||||
timeout(time: 5, unit: 'MINUTES') {
|
timeout(time: 5, unit: 'MINUTES') {
|
||||||
def qualityGate = waitForQualityGate abortPipeline: true
|
def qualityGate = waitForQualityGate abortPipeline: true
|
||||||
if (qualityGate.status != 'OK') {
|
if (qualityGate.status != 'OK') {
|
||||||
error "Quality Gate failed: ${qualityGate.status}"
|
error "Quality Gate failed: ${qualityGate.status}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stage('Clean Workspace') {
|
stage('Clean Workspace') {
|
||||||
@@ -42,84 +38,51 @@ pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def runBranchBuild = { agentLabel, workspaceDir ->
|
||||||
|
node(agentLabel) {
|
||||||
|
echo "Building on branch ${env.BRANCH_NAME}"
|
||||||
|
|
||||||
|
stage('Git Pull') {
|
||||||
|
dir(workspaceDir) {
|
||||||
|
withCredentials([gitUsernamePassword(credentialsId: 'gitlab')]) {
|
||||||
|
sh 'git stash push main.go && git status && git fetch && git pull && git stash list | grep -q . && git stash pop || true'
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
switch(env.BRANCH_NAME) {
|
switch(env.BRANCH_NAME) {
|
||||||
case 'main':
|
|
||||||
node('uess-prod-agent') {
|
|
||||||
echo "Building on branch ${env.BRANCH_NAME}"
|
|
||||||
|
|
||||||
stage('Git Pull') {
|
|
||||||
dir(WORKSPACE_DIR) {
|
|
||||||
withCredentials([gitUsernamePassword(credentialsId: 'gitlab')]) {
|
|
||||||
sh 'git stash push main.go && git status && git fetch && git pull && git stash pop'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'develop':
|
case 'develop':
|
||||||
node('uess-dev-agent') {
|
runBranchBuild('uess-dev-agent', env.WORKSPACE_DEV_DIR)
|
||||||
echo "Building on branch ${env.BRANCH_NAME}"
|
break;
|
||||||
|
|
||||||
stage('Git Pull') {
|
case 'main':
|
||||||
dir(WORKSPACE_DEV_DIR) {
|
runBranchBuild('uess-prod-agent', env.WORKSPACE_PROD_DIR)
|
||||||
withCredentials([gitUsernamePassword(credentialsId: 'gitlab')]) {
|
break;
|
||||||
sh 'git stash push main.go && git status && git fetch && git pull && git stash pop'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Restart Docker') {
|
|
||||||
sh 'docker container restart main-authorization-1'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'uat':
|
case 'uat':
|
||||||
node('uess-uat-agent') {
|
runBranchBuild('uess-uat-agent', env.WORKSPACE_UAT_DIR)
|
||||||
echo "Building on branch ${env.BRANCH_NAME}"
|
break;
|
||||||
|
|
||||||
stage('Git Pull') {
|
|
||||||
dir(WORKSPACE_UAT_DIR) {
|
|
||||||
withCredentials([gitUsernamePassword(credentialsId: 'gitlab')]) {
|
|
||||||
sh 'git stash push main.go && git status && git fetch && git pull && git stash pop'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'sqa':
|
case 'sqa':
|
||||||
node('uess-sqa-agent') {
|
runBranchBuild('uess-sqa-agent', env.WORKSPACE_SQA_DIR)
|
||||||
echo "Building on branch ${env.BRANCH_NAME}"
|
break;
|
||||||
|
|
||||||
stage('Git Pull') {
|
|
||||||
dir(WORKSPACE_SQA_DIR) {
|
|
||||||
withCredentials([gitUsernamePassword(credentialsId: 'gitlab')]) {
|
|
||||||
sh 'git stash push main.go && git status && git fetch && git pull && git stash pop'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'vapt':
|
case 'vapt':
|
||||||
node('uess-vapt-agent') {
|
runBranchBuild('uess-vapt-agent', env.WORKSPACE_VAPT_DIR)
|
||||||
echo "Building on branch ${env.BRANCH_NAME}"
|
break;
|
||||||
|
|
||||||
stage('Git Pull') {
|
|
||||||
dir(WORKSPACE_VAPT_DIR) {
|
|
||||||
withCredentials([gitUsernamePassword(credentialsId: 'gitlab')]) {
|
|
||||||
sh 'git stash push main.go && git status && git fetch && git pull && git stash pop'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
error "Branch ${env.BRANCH_NAME} is not supported."
|
error "Unsupported branch for deployment: ${env.BRANCH_NAME}"
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user