Edit Jenkinsfile
This commit is contained in:
Vendored
+33
-70
@@ -2,7 +2,7 @@ pipeline {
|
||||
agent any
|
||||
|
||||
environment {
|
||||
WORKSPACE_DIR = '/home/jenkins/prod/authz'
|
||||
WORKSPACE_PROD_DIR = '/home/jenkins/prod/authz'
|
||||
WORKSPACE_DEV_DIR = '/home/jenkins/dev/authz'
|
||||
WORKSPACE_UAT_DIR = '/home/jenkins/uat/authz'
|
||||
WORKSPACE_SQA_DIR = '/home/jenkins/sqa/authz'
|
||||
@@ -17,24 +17,20 @@ pipeline {
|
||||
def SCANNER_HOME = tool 'SonarScanner'
|
||||
|
||||
stage('SonarQube Analysis') {
|
||||
|
||||
withSonarQubeEnv('SonarQube') {
|
||||
sh "${SCANNER_HOME}/bin/sonar-scanner"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
stage('Quality Gate') {
|
||||
|
||||
script {
|
||||
timeout(time: 5, unit: 'MINUTES') {
|
||||
def qualityGate = waitForQualityGate abortPipeline: true
|
||||
if (qualityGate.status != 'OK') {
|
||||
error "Quality Gate failed: ${qualityGate.status}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
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':
|
||||
node('uess-dev-agent') {
|
||||
echo "Building on branch ${env.BRANCH_NAME}"
|
||||
runBranchBuild('uess-dev-agent', env.WORKSPACE_DEV_DIR)
|
||||
break;
|
||||
|
||||
stage('Git Pull') {
|
||||
dir(WORKSPACE_DEV_DIR) {
|
||||
withCredentials([gitUsernamePassword(credentialsId: 'gitlab')]) {
|
||||
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 'main':
|
||||
runBranchBuild('uess-prod-agent', env.WORKSPACE_PROD_DIR)
|
||||
break;
|
||||
|
||||
case 'uat':
|
||||
node('uess-uat-agent') {
|
||||
echo "Building on branch ${env.BRANCH_NAME}"
|
||||
|
||||
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;
|
||||
runBranchBuild('uess-uat-agent', env.WORKSPACE_UAT_DIR)
|
||||
break;
|
||||
|
||||
case 'sqa':
|
||||
node('uess-sqa-agent') {
|
||||
echo "Building on branch ${env.BRANCH_NAME}"
|
||||
|
||||
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;
|
||||
runBranchBuild('uess-sqa-agent', env.WORKSPACE_SQA_DIR)
|
||||
break;
|
||||
|
||||
case 'vapt':
|
||||
node('uess-vapt-agent') {
|
||||
echo "Building on branch ${env.BRANCH_NAME}"
|
||||
|
||||
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;
|
||||
runBranchBuild('uess-vapt-agent', env.WORKSPACE_VAPT_DIR)
|
||||
break;
|
||||
|
||||
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