From 65ba8beb69008add63ba8e85f3f774d82f44ccb6 Mon Sep 17 00:00:00 2001 From: F04C Date: Tue, 24 Mar 2026 16:36:16 +0800 Subject: [PATCH] added jenkinsfile --- Jenkinsfile | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..a5e47b6 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,125 @@ +pipeline { + agent any + + environment { + WORKSPACE_DIR = '/home/jenkins/prod/authn' + WORKSPACE_DEV_DIR = '/home/jenkins/dev/authn' + WORKSPACE_UAT_DIR = '/home/jenkins/uat/authn' + WORKSPACE_SQA_DIR = '/home/jenkins/sqa/authn' + WORKSPACE_VAPT_DIR = '/home/jenkins/vapt/authn' + + } + + stages { + stage('Build') { + steps { + script { + 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') { + cleanWs() + } + + + 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}" + + 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-authentication-1' + } + } + 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; + + 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; + + 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; + + default: + error "Branch ${env.BRANCH_NAME} is not supported." + } + } + } + } + } +}