diff --git a/be/be-acp/ci-acp-backend.Jenkinsfile b/be/be-acp/ci-acp-backend.Jenkinsfile index 58b6b06..25fa2b9 100644 --- a/be/be-acp/ci-acp-backend.Jenkinsfile +++ b/be/be-acp/ci-acp-backend.Jenkinsfile @@ -123,7 +123,7 @@ pipeline { success { echo "Job '${env.JOB_NAME}' completed successfully. Attempting to trigger Job '${TRIGGER_JOB_NAME}'..." script { - def message = "Build thành công : API - Dự án ${env.PROJECT_NAME} ${currentBuild.fullDisplayName}\n${env.BUILD_URL} \n Đang tiến hành Deploy...!" + def message = "Build thành công : API - 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 { @@ -145,7 +145,7 @@ pipeline { } failure { script { - def message = "Build thất bại: API - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n Kiểm tra tại đây ${env.BUILD_URL}." + def message = "Build thất bại: API - 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}\"" } } diff --git a/be/be-portal/ci-portal-backend.Jenkinsfile b/be/be-portal/ci-portal-backend.Jenkinsfile index 12782f5..2cb42c6 100644 --- a/be/be-portal/ci-portal-backend.Jenkinsfile +++ b/be/be-portal/ci-portal-backend.Jenkinsfile @@ -125,7 +125,7 @@ pipeline { success { echo "Job '${env.JOB_NAME}' completed successfully. Attempting to trigger Job '${TRIGGER_JOB_NAME}'..." script { - def message = "Build thành công : API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME} ${currentBuild.fullDisplayName}\n${env.BUILD_URL} \n Đang tiến hành Deploy...!" + def message = "Build thành công : API - 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 { @@ -149,7 +149,7 @@ pipeline { failure { failure { script { - def message = "Build thất bại: API - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n Kiểm tra tại đây ${env.BUILD_URL}." + def message = "Build thất bại: API - 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}\"" } } diff --git a/fe/fe-acp/ci-acp-frontend.Jenkinsfile b/fe/fe-acp/ci-acp-frontend.Jenkinsfile deleted file mode 100644 index 1225215..0000000 --- a/fe/fe-acp/ci-acp-frontend.Jenkinsfile +++ /dev/null @@ -1,269 +0,0 @@ -pipeline { - agent any - parameters { - choice(name: 'ENV', choices: ['uat', 'prod'], description: 'Choose Environment') - } - 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' - TRIGGER_JOB_NAME = 'CD_FE_ACP' - METADATA_FILENAME = "${params.ENV}_${PROJECT_NAME}_metadata.json" - - NUXT_BUILD_FOLDER_PATH = "${env.WORKSPACE}" - OUTPUT_FOLDER_PATH = "${params.ENV}-${PROJECT_NAME}-output" //thư mục .output (sau khi build xong) - COMMAND_NUXT_INSTALL = 'npm install' //command install dependencies - COMMAND_NUXT_BUILD_UAT = "NITRO_OUTPUT=${OUTPUT_FOLDER_PATH} yarn linux-builder" // command build MT uat - COMMAND_NUXT_BUILD_PROD = "NITRO_OUTPUT=${OUTPUT_FOLDER_PATH} yarn linux-builder:production" // command build MT prod - - COMPRESSED_FILE_NAME = "${params.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/${PROJECT_NAME}-frontend" - GROUP_ID = 'vn.kinhtedothi' - ARTIFACT_ID = "${params.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 - } - - 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 { - switch (params.ENV) { - case 'uat': - env.COMMAND_NUXT_BUILD = COMMAND_NUXT_BUILD_UAT - break - case 'prod': - env.COMMAND_NUXT_BUILD = COMMAND_NUXT_BUILD_PROD - break - default: - error "Unsupported environment: ${params.ENV}" - } - 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 { - try { - def buildResult = build job: "${TRIGGER_JOB_NAME}", parameters:[ - string(name: 'ENV', value: params.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 - } - } - } - } -} - -//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(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-acp/ci-prod-acp-frontend.Jenkinsfile b/fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile index a8bff0f..373ebb0 100644 --- a/fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile +++ b/fe/fe-acp/ci-prod-acp-frontend.Jenkinsfile @@ -102,7 +102,7 @@ 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} ${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} \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 { @@ -124,7 +124,7 @@ pipeline { } failure { script { - def message = "Build thất bại: FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME}, ${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} \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}\"" } } diff --git a/fe/fe-acp/ci-uat-acp-frontend.Jenkinsfile b/fe/fe-acp/ci-uat-acp-frontend.Jenkinsfile index 6abb4ba..de6de19 100644 --- a/fe/fe-acp/ci-uat-acp-frontend.Jenkinsfile +++ b/fe/fe-acp/ci-uat-acp-frontend.Jenkinsfile @@ -105,7 +105,7 @@ 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} ${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} \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 { @@ -127,7 +127,7 @@ pipeline { } failure { script { - def message = "Build thất bại: FRONTEND - Môi trường ${env.ENV} - Dự án ${env.PROJECT_NAME}, ${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} \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}\"" } }