From 27c4b620e4f4e90faa900d24a2f576f1af330454 Mon Sep 17 00:00:00 2001 From: thienqb123456 Date: Fri, 28 Feb 2025 17:24:42 +0700 Subject: [PATCH] update --- fe/fe-acp/cd-acp-frontend.Jenkinsfile | 5 +- fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile | 277 ----------------- fe/fe-portal/cd-portal-frontend.Jenkinsfile | 11 +- .../ci-prod-portal-frontend.Jenkinsfile | 280 ------------------ .../ci-uat-portal-frontend.Jenkinsfile | 21 +- 5 files changed, 21 insertions(+), 573 deletions(-) delete mode 100644 fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile delete mode 100644 fe/fe-portal/ci-prod-portal-frontend.Jenkinsfile diff --git a/fe/fe-acp/cd-acp-frontend.Jenkinsfile b/fe/fe-acp/cd-acp-frontend.Jenkinsfile index f87fb93..01ab8a4 100644 --- a/fe/fe-acp/cd-acp-frontend.Jenkinsfile +++ b/fe/fe-acp/cd-acp-frontend.Jenkinsfile @@ -1,7 +1,7 @@ pipeline { agent any parameters { - choice(name: 'ENV', choices: ['prod', 'uat', 'beta'], description: 'Choose Environment') + choice(name: 'ENV', choices: ['uat', 'beta'], description: 'Choose Environment') string(name: 'CI_JOB_BUILD_NUMBER', defaultValue: '', description: 'Build number of CI Job') } environment { @@ -35,9 +35,6 @@ pipeline { case 'uat': env.CI_JOB_NAME = env.CI_JOB_NAME_UAT break - case 'prod': - env.CI_JOB_NAME = env.CI_JOB_NAME_PROD - break case 'beta': env.CI_JOB_NAME = env.CI_JOB_NAME_BETA break diff --git a/fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile b/fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile deleted file mode 100644 index c2740e9..0000000 --- a/fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile +++ /dev/null @@ -1,277 +0,0 @@ -pipeline { - agent any - options { disableConcurrentBuilds(abortPrevious: true) } - environment { - GIT_CREDENTIALSID = 'b03f36c4-bba3-4764-94ca-b620651b2a68' - GIT_URL = 'http://work.gct.com.vn/anhln/NSG_2025.git' - GIT_BRANCH = 'main' - - PROJECT_NAME = 'acp' - ENV = 'prod' - TRIGGER_JOB_NAME = 'CD_FE_ACP' - METADATA_FILENAME = "${env.ENV}_${PROJECT_NAME}_metadata.json" - - NUXT_BUILD_FOLDER_PATH = "${env.WORKSPACE}" - OUTPUT_FOLDER_PATH = "${env.ENV}-${PROJECT_NAME}-output" //thư mục .output (sau khi build xong) - COMMAND_NUXT_INSTALL = 'npm install' //command install dependencies - COMMAND_NUXT_BUILD = "NITRO_OUTPUT=${OUTPUT_FOLDER_PATH} yarn linux-builder:production" // command build MT prod - - COMPRESSED_FILE_NAME = "${env.ENV}_${PROJECT_NAME}_output.zip" // tên file nén - COMPRESSED_FILE_PATH = "${env.WORKSPACE }/${COMPRESSED_FILE_NAME}" - - NEXUS_CREDENTIALS = credentials('Nexus_credential') - NEXUS_REPO_URL = "https://nexus.gct.com.vn/repository/${env.ENV}-${PROJECT_NAME}-frontend" - GROUP_ID = 'vn.kinhtedothi' - ARTIFACT_ID = "${env.ENV}-${PROJECT_NAME}-frontend" - PACKAGING = 'zip' - VERSION = '1.0.0' // Phiên bản cơ bản - - TIMESTAMP = new Date().format('yyyyMMdd.HH', TimeZone.getTimeZone('UTC')) - FULL_VERSION = "${env.VERSION}-${env.TIMESTAMP}-${env.BUILD_NUMBER}" // Tạo phiên bản hoàn chỉnh - - TELEGRAM_CHAT_ID = -4678013464 - TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN') - } - - stages { - stage('Checkout') { - steps { - // Checkout mã nguồn từ Gitea - checkoutFromGit(env.GIT_URL as String, env.GIT_CREDENTIALSID as String, env.GIT_BRANCH as String) - } - } - - stage('Install Dependencies') { - steps { - script { - installDependencies(env.NUXT_BUILD_FOLDER_PATH as String, env.COMMAND_NUXT_INSTALL as String) - } - } - } - - stage('Build') { - steps { - script { - buildProject(env.NUXT_BUILD_FOLDER_PATH as String, env.COMMAND_NUXT_BUILD as String) - } - } - } - - stage('Package (Compress Output Files)') { - steps { - compressItems(env.COMPRESSED_FILE_PATH, env.OUTPUT_FOLDER_PATH) - } - } - - stage('Upload to Nexus') { - steps { - script { - String groupPath = env.GROUP_ID.replace('.', '/') - env.NEXUS_URL = "${env.NEXUS_REPO_URL}/${groupPath}/${env.ARTIFACT_ID}/${env.VERSION}" - env.NEXUS_ARTIFACT_NAME = "${env.ARTIFACT_ID}-${env.FULL_VERSION}.${env.PACKAGING}" - - String nexusUploadUrl = "${env.NEXUS_URL}/${env.NEXUS_ARTIFACT_NAME}" - - uploadToNexus( - env.NEXUS_CREDENTIALS_USR, - env.NEXUS_CREDENTIALS_PSW, - env.COMPRESSED_FILE_PATH, - nexusUploadUrl) - } - } - } - - stage('Create Metadata File') { - steps { - createMetadataFile( - env.METADATA_FILENAME, - env.GROUP_ID, - env.ARTIFACT_ID, - env.VERSION, - env.NEXUS_URL, - env.NEXUS_ARTIFACT_NAME) - echo "metadataFileName: ${env.METADATA_FILENAME}" - archiveArtifacts artifacts: "${env.METADATA_FILENAME}", allowEmptyArchive: false - } - } - } - - post { - always { - echo 'Pipeline execution finished.' - } - success { - echo "Job '${env.JOB_NAME}' completed successfully. Attempting to trigger Job '${TRIGGER_JOB_NAME}'..." - script { - def message = "✅Build thành công : FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} \n ${currentBuild.fullDisplayName}\n${env.BUILD_URL} \n Đang tiến hành Deploy...!" - sh "curl -s -X POST https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${env.TELEGRAM_CHAT_ID} -d text=\"${message}\"" - } - script { - try { - def buildResult = build job: "${TRIGGER_JOB_NAME}", parameters:[ - string(name: 'ENV', value: env.ENV), - string(name: 'CI_JOB_BUILD_NUMBER', value: env.BUILD_NUMBER) - ], - propagate: false - if (buildResult.result != 'SUCCESS') { - echo "[WARNING] Job 2 failed with result: ${buildResult.result}" - } - } - catch (Exception e) { - echo "[ERROR] Failed to trigger job: ${TRIGGER_JOB_NAME}. Error: ${e.message}" - throw e - } - } - } - failure { - script { - def message = "❌Build thất bại: FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} \n ${currentBuild.fullDisplayName}\n Kiểm tra tại đây ${env.BUILD_URL}." - sh "curl -s -X POST https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${env.TELEGRAM_CHAT_ID} -d text=\"${message}\"" - } - } - } -} - -//Thienvv- hàm checkout git -void checkoutFromGit(String gitUrl, String credentialsId, String branch) { - echo 'Start checkoutFromGit' - try { - checkout([$class : 'GitSCM', - userRemoteConfigs: [[url: gitUrl, credentialsId: credentialsId]], - branches : [[name: "*/${branch}"]]]) - } catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } -} - -// Thienvv - hàm installDependencies -void installDependencies(String buildFolderPath, String command) { - echo 'Start installDependencies' - try { - if (!fileExists(buildFolderPath)) { - error "buildFolderPath is not exist : ${buildFolderPath}" - } - - dir("${buildFolderPath}") { - Integer result = sh(script: "${command}", returnStatus: true) - - echo "result:${result}" - - if (result == 0) { - echo 'install Dependencies successfully.' - } else { - error "install Dependencies failed with status: ${result}" - } - } - } catch (Exception e) { - error "Restore failed: ${e.message}" - } -} - -//Thienvv - build project -void buildProject(String buildFolderPath, String command) { - echo 'Start buildProject' - try { - if (!fileExists(buildFolderPath)) { - error "buildFolderPath is not exist : ${buildFolderPath}" - } - // Build dự án Nuxt.js - dir("${buildFolderPath}") { - Integer result = sh(script: "${command}", returnStatus: true) - - echo "result:${result}" - - if (result == 0) { - echo 'Build Project successfully' - } else { - error "Build Project failed, status: ${result}" - } - } - } catch (Exception e) { - error "Build Project failed: ${e.message}" - } -} - -//Thienvv - nén file -void compressItems(String compressedFilePath, String parentFolderPath) { - echo "Starting compression of the entire folder into a zip file : ${compressedFilePath}" - try { - if (fileExists(compressedFilePath)) { - echo "Old ZIP file exists. Deleting: ${compressedFilePath}" - sh "rm -f ${compressedFilePath}" - } else { - echo 'No old ZIP file found.' - } - - if (!fileExists(parentFolderPath)) { - error "parentFolderPath is not exist : ${parentFolderPath}" - } - - dir(parentFolderPath) { - // Thực hiện lệnh zip để nén tất cả các file trong thư mục - Integer result = sh(script: "zip -r ${compressedFilePath} * ", returnStatus: true) - - // Kiểm tra kết quả - if (result == 0) { - echo "compressItems completed successfully: ${compressedFilePath}" - } else { - error "compressItems failed with exit code: ${result}." - } - } - } catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } -} - -void uploadToNexus(String nexusUsername, String nexusPassword, String compressedFilePath, String uploadUrl) { - echo "Starting upload ${compressedFilePath} To Nexus" - try { - // Truyền các biến môi trường vào lệnh sh mà không lộ ra trong log - String result = sh(script: """ - curl -u ${nexusUsername}:${nexusPassword} --upload-file ${compressedFilePath} ${uploadUrl} -w '%{http_code}' - """, returnStdout: true).trim() - - if (result == '200' || result == '201') { - echo 'uploadToNexus successfully' - } else { - error "uploadToNexus failed, HTTP status: ${result}" - } - } - catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } -} - -void createMetadataFile( - String metadataFileName, - String groupId, - String artifactId, - String version, - String nexusUrl, - String nexusArtifactName) { - echo 'Starting create metadata file' - try { - // Tạo metadata - metadata = [ - groupId: groupId, - artifactId: artifactId, - version: version, - nexusUrl: nexusUrl, - nexusArtifactName: nexusArtifactName - ] - - // Ghi metadata vào file JSON - writeJSON file: "${metadataFileName}", json: metadata - - if (!fileExists(metadataFileName)) { - error "metadataFileName is not exist : ${metadataFileName}" - } - } - catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } - } diff --git a/fe/fe-portal/cd-portal-frontend.Jenkinsfile b/fe/fe-portal/cd-portal-frontend.Jenkinsfile index 29a791e..5d303d5 100644 --- a/fe/fe-portal/cd-portal-frontend.Jenkinsfile +++ b/fe/fe-portal/cd-portal-frontend.Jenkinsfile @@ -1,16 +1,16 @@ pipeline { agent any parameters { - choice(name: 'ENV', choices: ['prod', 'uat', 'beta'], description: 'Choose Environment') + choice(name: 'ENV', choices: ['uat', 'beta'], description: 'Choose Environment') + choice(name: 'PORTAL_NAME', choices: ['ktdt', 'hnt'], description: 'Choose SITE NAME') string(name: 'CI_JOB_BUILD_NUMBER', defaultValue: '', description: 'Build number of CI Job') } environment { PROJECT_NAME = 'portal' CI_JOB_NAME_UAT = 'CI-UAT-FE-PORTAL' // tên của job build code môi trường uat - CI_JOB_NAME_PROD = 'CI-PROD-FE-PORTAL' // tên của job build code môi trường prod CI_JOB_NAME_BETA = 'CI-BETA-FE-PORTAL' // tên của job build code môi trường prod - CI_JOB_METADATA_FILENAME = "${params.ENV}_${PROJECT_NAME}_metadata.json" // tên file metadata đã được lưu từ job build code + CI_JOB_METADATA_FILENAME = "${env.ENV}_${env.PROJECT_NAME}_${params.PORTAL_NAME}_metadata.json" // tên file metadata đã được lưu từ job build code GIT_PAT_CREDENTIALS_ID = 'b03f36c4-bba3-4764-94ca-b620651b2a68' // Id của Personal Access Token lưu trên jenkins GIT_ANSIBLE_URL = 'work.gct.com.vn/thienvv/nsg_ansible.git' @@ -35,8 +35,6 @@ pipeline { case 'uat': env.CI_JOB_NAME = env.CI_JOB_NAME_UAT break - case 'prod': - env.CI_JOB_NAME = env.CI_JOB_NAME_PROD case 'beta': env.CI_JOB_NAME = env.CI_JOB_NAME_BETA break @@ -84,6 +82,7 @@ pipeline { env.ANSIBLE_PLAYBOOK_PATH, params.ENV, env.PROJECT_NAME, + env.PORTAL_NAME, env.NEXUS_URL, env.NEXUS_ARTIFACT_NAME, env.NEXUS_CREDENTIALS_USR, @@ -209,6 +208,7 @@ def triggerAnsible( String playbookPath, String deployENV, String projectName, + String portalName, String nexusUrl, String nexusArtifactName, String nexusUsername, @@ -222,6 +222,7 @@ def triggerAnsible( ansible-playbook -i ${inventoryPath} ${playbookPath} \\ -e 'deploy_env=${deployENV} \\ project_name=${projectName} \\ + portal_name=${portalName} \\ nexus_url=${nexusUrl} \\ artifact_name=${nexusArtifactName} \\ nexus_username=${nexusUsername} \\ diff --git a/fe/fe-portal/ci-prod-portal-frontend.Jenkinsfile b/fe/fe-portal/ci-prod-portal-frontend.Jenkinsfile deleted file mode 100644 index fd51ed2..0000000 --- a/fe/fe-portal/ci-prod-portal-frontend.Jenkinsfile +++ /dev/null @@ -1,280 +0,0 @@ -pipeline { - agent any - options { disableConcurrentBuilds(abortPrevious: true) } - environment { - GIT_CREDENTIALSID = 'b03f36c4-bba3-4764-94ca-b620651b2a68' - GIT_URL = 'http://work.gct.com.vn/anhln/PORTAL_2025.git' - GIT_BRANCH = 'main' - - ENV = 'prod' - PROJECT_NAME = 'portal' - TRIGGER_JOB_NAME = 'CD-FE-PORTAL' - METADATA_FILENAME = "${env.ENV}_${env.PROJECT_NAME}_metadata.json" - - NUXT_BUILD_FOLDER_PATH = "${env.WORKSPACE}" - OUTPUT_FOLDER_PATH = ".output" //thư mục .output (sau khi build xong) - COMMAND_NUXT_INSTALL = 'npm install' //command install dependencies - COMMAND_NUXT_BUILD = "yarn build:production" // command build MT prod - - COMPRESSED_FILE_NAME = "${env.ENV}_${env.PROJECT_NAME}_output.zip" // tên file nén - COMPRESSED_FILE_PATH = "${env.WORKSPACE }/${env.COMPRESSED_FILE_NAME}" - - NEXUS_CREDENTIALS = credentials('Nexus_credential') - NEXUS_REPO_URL = "https://nexus.gct.com.vn/repository/${env.ENV}-${env.PROJECT_NAME}-frontend" - GROUP_ID = 'vn.kinhtedothi' - ARTIFACT_ID = "${env.ENV}-${env.PROJECT_NAME}-frontend" - PACKAGING = 'zip' - VERSION = '1.0.0' // Phiên bản cơ bản - - TIMESTAMP = new Date().format('yyyyMMdd.HH', TimeZone.getTimeZone('UTC')) - FULL_VERSION = "${env.VERSION}-${env.TIMESTAMP}-${env.BUILD_NUMBER}" // Tạo phiên bản hoàn chỉnh - - TELEGRAM_CHAT_ID = -4678013464 - TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN') - } - - stages { - stage('Checkout') { - steps { - // Checkout mã nguồn từ Gitea - checkoutFromGit(env.GIT_URL as String, env.GIT_CREDENTIALSID as String, env.GIT_BRANCH as String) - } - } - - stage('Install Dependencies') { - steps { - script { - installDependencies(env.NUXT_BUILD_FOLDER_PATH as String, env.COMMAND_NUXT_INSTALL as String) - } - } - } - - stage('Build') { - steps { - script { - buildProject(env.NUXT_BUILD_FOLDER_PATH as String, env.COMMAND_NUXT_BUILD as String) - } - } - } - - stage('Package (Compress Output Files)') { - steps { - compressItems(env.COMPRESSED_FILE_PATH, env.OUTPUT_FOLDER_PATH) - } - } - - stage('Upload to Nexus') { - steps { - script { - String groupPath = env.GROUP_ID.replace('.', '/') - env.NEXUS_URL = "${env.NEXUS_REPO_URL}/${groupPath}/${env.ARTIFACT_ID}/${env.VERSION}" - env.NEXUS_ARTIFACT_NAME = "${env.ARTIFACT_ID}-${env.FULL_VERSION}.${env.PACKAGING}" - - echo "NEXUS_URL : ${env.NEXUS_URL}" - echo "NEXUS_ARTIFACT_NAME : ${env.NEXUS_ARTIFACT_NAME}" - - String nexusUploadUrl = "${env.NEXUS_URL}/${env.NEXUS_ARTIFACT_NAME}" - - uploadToNexus( - env.NEXUS_CREDENTIALS_USR, - env.NEXUS_CREDENTIALS_PSW, - env.COMPRESSED_FILE_PATH, - nexusUploadUrl) - } - } - } - - stage('Create Metadata File') { - steps { - createMetadataFile( - env.METADATA_FILENAME, - env.GROUP_ID, - env.ARTIFACT_ID, - env.VERSION, - env.NEXUS_URL, - env.NEXUS_ARTIFACT_NAME) - echo "metadataFileName: ${env.METADATA_FILENAME}" - archiveArtifacts artifacts: "${env.METADATA_FILENAME}", allowEmptyArchive: false - } - } - } - - post { - always { - echo 'Pipeline execution finished.' - } - success { - echo "Job '${env.JOB_NAME}' completed successfully. Attempting to trigger Job '${TRIGGER_JOB_NAME}'..." - script { - def message = "✅Build thành công : FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} \n ${currentBuild.fullDisplayName}\n${env.BUILD_URL} \n Đang tiến hành Deploy...!" - sh "curl -s -X POST https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${env.TELEGRAM_CHAT_ID} -d text=\"${message}\"" - } - script { - try { - def buildResult = build job: "${TRIGGER_JOB_NAME}", parameters:[ - string(name: 'ENV', value: env.ENV), - string(name: 'CI_JOB_BUILD_NUMBER', value: env.BUILD_NUMBER) - ], - propagate: false - if (buildResult.result != 'SUCCESS') { - echo "[WARNING] Job 2 failed with result: ${buildResult.result}" - } - } - catch (Exception e) { - echo "[ERROR] Failed to trigger job: ${TRIGGER_JOB_NAME}. Error: ${e.message}" - throw e - } - } - } - failure { - script { - def message = "❌Build thất bại: FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} \n ${currentBuild.fullDisplayName}\n Kiểm tra tại đây ${env.BUILD_URL}." - sh "curl -s -X POST https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${env.TELEGRAM_CHAT_ID} -d text=\"${message}\"" - } - } - } -} - -//Thienvv- hàm checkout git -void checkoutFromGit(String gitUrl, String credentialsId, String branch) { - echo 'Start checkoutFromGit' - try { - checkout([$class : 'GitSCM', - userRemoteConfigs: [[url: gitUrl, credentialsId: credentialsId]], - branches : [[name: "*/${branch}"]]]) - } catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } -} - -// Thienvv - hàm installDependencies -void installDependencies(String buildFolderPath, String command) { - echo 'Start installDependencies' - try { - if (!fileExists(buildFolderPath)) { - error "buildFolderPath is not exist : ${buildFolderPath}" - } - - dir("${buildFolderPath}") { - Integer result = sh(script: "${command}", returnStatus: true) - - echo "result:${result}" - - if (result == 0) { - echo 'install Dependencies successfully.' - } else { - error "install Dependencies failed with status: ${result}" - } - } - } catch (Exception e) { - error "Restore failed: ${e.message}" - } -} - -//Thienvv - build project -void buildProject(String buildFolderPath, String command) { - echo 'Start buildProject' - try { - if (!fileExists(buildFolderPath)) { - error "buildFolderPath is not exist : ${buildFolderPath}" - } - // Build dự án Nuxt.js - dir("${buildFolderPath}") { - Integer result = sh(script: "${command}", returnStatus: true) - - echo "result:${result}" - - if (result == 0) { - echo 'Build Project successfully' - } else { - error "Build Project failed, status: ${result}" - } - } - } catch (Exception e) { - error "Build Project failed: ${e.message}" - } -} - -//Thienvv - nén file -void compressItems(String compressedFilePath, String parentFolderPath) { - echo "Starting compression of the entire folder into a zip file : ${compressedFilePath}" - try { - if (fileExists(compressedFilePath)) { - echo "Old ZIP file exists. Deleting: ${compressedFilePath}" - sh "rm -f ${compressedFilePath}" - } else { - echo 'No old ZIP file found.' - } - - if (!fileExists(parentFolderPath)) { - error "parentFolderPath is not exist : ${parentFolderPath}" - } - - dir(parentFolderPath) { - // Thực hiện lệnh zip để nén tất cả các file trong thư mục - Integer result = sh(script: "zip -r ${compressedFilePath} * ", returnStatus: true) - - // Kiểm tra kết quả - if (result == 0) { - echo "compressItems completed successfully: ${compressedFilePath}" - } else { - error "compressItems failed with exit code: ${result}." - } - } - } catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } -} - -void uploadToNexus(String nexusUsername, String nexusPassword, String compressedFilePath, String uploadUrl) { - echo "Starting upload ${compressedFilePath} To Nexus" - try { - // Truyền các biến môi trường vào lệnh sh mà không lộ ra trong log - String result = sh(script: """ - curl -u ${nexusUsername}:${nexusPassword} --upload-file ${compressedFilePath} ${uploadUrl} -w '%{http_code}' - """, returnStdout: true).trim() - - if (result == '200' || result == '201') { - echo 'uploadToNexus successfully' - } else { - error "uploadToNexus failed, HTTP status: ${result}" - } - } - catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } -} - -void createMetadataFile( - String metadataFileName, - String groupId, - String artifactId, - String version, - String nexusUrl, - String nexusArtifactName) { - echo 'Starting create metadata file' - try { - // Tạo metadata - metadata = [ - groupId: groupId, - artifactId: artifactId, - version: version, - nexusUrl: nexusUrl, - nexusArtifactName: nexusArtifactName - ] - - // Ghi metadata vào file JSON - writeJSON file: "${metadataFileName}", json: metadata - - if (!fileExists(metadataFileName)) { - error "metadataFileName is not exist : ${metadataFileName}" - } - } - catch (Exception e) { - echo "[ERROR] Unexpected error: ${e.message}" - throw e - } - } diff --git a/fe/fe-portal/ci-uat-portal-frontend.Jenkinsfile b/fe/fe-portal/ci-uat-portal-frontend.Jenkinsfile index 58af20c..8812232 100644 --- a/fe/fe-portal/ci-uat-portal-frontend.Jenkinsfile +++ b/fe/fe-portal/ci-uat-portal-frontend.Jenkinsfile @@ -1,6 +1,9 @@ pipeline { agent any options { disableConcurrentBuilds(abortPrevious: true) } + parameters { + choice(name: 'PORTAL_NAME', choices: ['ktdt', 'hnt'], description: 'Choose PORTAL NAME') + } environment { GIT_CREDENTIALSID = 'b03f36c4-bba3-4764-94ca-b620651b2a68' GIT_URL = 'http://work.gct.com.vn/anhln/PORTAL_2025.git' @@ -8,21 +11,23 @@ pipeline { ENV = 'uat' PROJECT_NAME = 'portal' + TRIGGER_JOB_NAME = 'CD-FE-PORTAL' - METADATA_FILENAME = "${env.ENV}_${env.PROJECT_NAME}_metadata.json" + METADATA_FILENAME = "${env.ENV}_${env.PROJECT_NAME}_${params.PORTAL_NAME}_metadata.json" NUXT_BUILD_FOLDER_PATH = "${env.WORKSPACE}" - OUTPUT_FOLDER_PATH = ".output" //thư mục .output (sau khi build xong) + OUTPUT_FOLDER_PATH = "${env.ENV}-${env.PROJECT_NAME}-${params.PORTAL_NAME}-output" //thư mục .output + COMMAND_NUXT_INSTALL = 'npm install' //command install dependencies COMMAND_NUXT_BUILD = "yarn build" // command build MT uat - COMPRESSED_FILE_NAME = "${env.ENV}_${env.PROJECT_NAME}_output.zip" // tên file nén + COMPRESSED_FILE_NAME = "${env.ENV}_${env.PROJECT_NAME}_${params.PORTAL_NAME}_output.zip" // tên file nén COMPRESSED_FILE_PATH = "${env.WORKSPACE }/${env.COMPRESSED_FILE_NAME}" NEXUS_CREDENTIALS = credentials('Nexus_credential') NEXUS_REPO_URL = "https://nexus.gct.com.vn/repository/${env.ENV}-${env.PROJECT_NAME}-frontend" GROUP_ID = 'vn.kinhtedothi' - ARTIFACT_ID = "${env.ENV}-${env.PROJECT_NAME}-frontend" + ARTIFACT_ID = "${env.ENV}-${env.PROJECT_NAME}-${params.PORTAL_NAME}-frontend" PACKAGING = 'zip' VERSION = '1.0.0' // Phiên bản cơ bản @@ -105,14 +110,16 @@ pipeline { success { echo "Job '${env.JOB_NAME}' completed successfully. Attempting to trigger Job '${TRIGGER_JOB_NAME}'..." script { - def message = "✅Build thành công : FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} \n ${currentBuild.fullDisplayName}\n${env.BUILD_URL} \n Đang tiến hành Deploy...!" + def message = "✅Build thành công : FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} - Site ${params.PORTAL_NAME} \n ${currentBuild.fullDisplayName}\n${env.BUILD_URL} \n Đang tiến hành Deploy...!" sh "curl -s -X POST https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${env.TELEGRAM_CHAT_ID} -d text=\"${message}\"" } script { try { def buildResult = build job: "${TRIGGER_JOB_NAME}", parameters:[ string(name: 'ENV', value: env.ENV), - string(name: 'CI_JOB_BUILD_NUMBER', value: env.BUILD_NUMBER) + string(name: 'PORTAL_NAME', value: params.PORTAL_NAME), + string(name: 'CI_JOB_BUILD_NUMBER', value: env.BUILD_NUMBER), + ], propagate: false if (buildResult.result != 'SUCCESS') { @@ -127,7 +134,7 @@ pipeline { } failure { script { - def message = "❌Build thất bại: FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} \n ${currentBuild.fullDisplayName}\n Kiểm tra tại đây ${env.BUILD_URL}." + def message = "❌Build thất bại: FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME} - Site ${params.PORTAL_NAME} \n ${currentBuild.fullDisplayName}\n Kiểm tra tại đây ${env.BUILD_URL}." sh "curl -s -X POST https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage -d chat_id=${env.TELEGRAM_CHAT_ID} -d text=\"${message}\"" } }