This commit is contained in:
thienqb123456
2025-03-04 17:18:05 +07:00
parent bdcdbf0c2f
commit c422a0caff
3 changed files with 19 additions and 12 deletions
+2 -2
View File
@@ -83,13 +83,13 @@ pipeline {
} }
success { success {
script { script {
def message = "✅Deploy thành công : API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n${env.BUILD_URL}" def message = "✅Deploy thành công : API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME} - Portal_Name ${params.PORTAL_NAME}, ${currentBuild.fullDisplayName}\n${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}\"" 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}\""
} }
} }
failure { failure {
script { script {
def message = "❌Deploy thất bại: API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n${env.BUILD_URL}" def message = "❌Deploy thất bại: API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME} - Portal_Name ${params.PORTAL_NAME}, ${currentBuild.fullDisplayName}\n${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}\"" 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}\""
} }
} }
+13 -6
View File
@@ -2,23 +2,27 @@ pipeline {
agent any agent any
parameters { parameters {
choice(name: 'ENV', choices: ['uat', 'beta'], description: 'Choose Environment') choice(name: 'ENV', choices: ['uat', 'beta'], description: 'Choose Environment')
choice(name: 'PORTAL_NAME', choices: ['ktdt', 'hnt'], description: 'Choose Portal')
string(name: 'CI_JOB_BUILD_NUMBER', defaultValue: '', description: 'Build number of CI Job') string(name: 'CI_JOB_BUILD_NUMBER', defaultValue: '', description: 'Build number of CI Job')
} }
environment { environment {
PROJECT_NAME = 'resource' PROJECT_NAME = 'resource'
CI_JOB_NAME = 'CI-BE-RESOURCE' // tên của job build code
CI_JOB_NAME = 'CI-BE-RESOURCE' // tên của job CI
CI_JOB_METADATA_FILENAME = "${PROJECT_NAME}_metadata.json" // tên file metadata đã được lưu từ ci job CI_JOB_METADATA_FILENAME = "${PROJECT_NAME}_metadata.json" // tên file metadata đã được lưu từ ci job
NEXUS_CREDENTIALS = credentials('Nexus_credential')
ANSIBLE_SSH_CONNECTION = 'root@103.166.183.172 -p 24700'
GIT_PAT_CREDENTIALS_ID = 'd3de261f-8f1e-470b-b6d1-2fb4965e0129' // Id của Personal Access Token lưu trên jenkins GIT_PAT_CREDENTIALS_ID = 'd3de261f-8f1e-470b-b6d1-2fb4965e0129' // Id của Personal Access Token lưu trên jenkins
GIT_ANSIBLE_URL = 'work.gct.com.vn/thienvv/nsg_ansible.git' GIT_ANSIBLE_URL = 'work.gct.com.vn/thienvv/nsg_ansible.git'
GIT_ANSIBLE_BRANCH = 'v2' GIT_ANSIBLE_BRANCH = 'v2'
NEXUS_CREDENTIALS = credentials('Nexus_credential')
ANSIBLE_SSH_CONNECTION = 'root@103.166.183.172 -p 24700'
ANSIBLE_FOLDER_PATH = '/srv/ansible_v2' ANSIBLE_FOLDER_PATH = '/srv/ansible_v2'
ANSIBLE_INVENTORY_PATH = "inventory/${params.ENV}.ini" ANSIBLE_INVENTORY_PATH = "inventory/${params.ENV}.ini"
ANSIBLE_PLAYBOOK_PATH = 'playbooks/deploy_be.yml' ANSIBLE_PLAYBOOK_PATH = 'playbooks/deploy_be_resource.yml'
TELEGRAM_CHAT_ID = -4678013464 TELEGRAM_CHAT_ID = -4678013464
TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN') TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN')
@@ -65,6 +69,7 @@ pipeline {
env.ANSIBLE_PLAYBOOK_PATH, env.ANSIBLE_PLAYBOOK_PATH,
params.ENV, params.ENV,
env.PROJECT_NAME, env.PROJECT_NAME,
params.PORTAL_NAME,
env.NEXUS_URL, env.NEXUS_URL,
env.NEXUS_ARTIFACT_NAME, env.NEXUS_ARTIFACT_NAME,
env.NEXUS_CREDENTIALS_USR, env.NEXUS_CREDENTIALS_USR,
@@ -79,13 +84,13 @@ pipeline {
} }
success { success {
script { script {
def message = "✅Deploy thành công : API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n${env.BUILD_URL}" def message = "✅Deploy thành công : API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME}- Portal_Name ${params.PORTAL_NAME}, ${currentBuild.fullDisplayName}\n${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}\"" 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}\""
} }
} }
failure { failure {
script { script {
def message = "❌Deploy thất bại: API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n${env.BUILD_URL}" def message = "❌Deploy thất bại: API - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME} - Portal_Name ${params.PORTAL_NAME}, ${currentBuild.fullDisplayName}\n${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}\"" 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}\""
} }
} }
@@ -190,6 +195,7 @@ def triggerAnsible(
String playbookPath, String playbookPath,
String deployENV, String deployENV,
String projectName, String projectName,
String portalName,
String nexusUrl, String nexusUrl,
String nexusArtifactName, String nexusArtifactName,
String nexusUsername, String nexusUsername,
@@ -203,6 +209,7 @@ def triggerAnsible(
ansible-playbook -i ${inventoryPath} ${playbookPath} \\ ansible-playbook -i ${inventoryPath} ${playbookPath} \\
-e 'deploy_env=${deployENV} \\ -e 'deploy_env=${deployENV} \\
project_name=${projectName} \\ project_name=${projectName} \\
portal_name=${portalName} \\
nexus_url=${nexusUrl} \\ nexus_url=${nexusUrl} \\
artifact_name=${nexusArtifactName} \\ artifact_name=${nexusArtifactName} \\
nexus_username=${nexusUsername} \\ nexus_username=${nexusUsername} \\
+2 -2
View File
@@ -97,13 +97,13 @@ pipeline {
} }
success { success {
script { script {
def message = "✅Deploy thành công : FRONTEND - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n${env.BUILD_URL}" def message = "✅Deploy thành công : FRONTEND - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME} - Portal_Name ${params.PORTAL_NAME}, ${currentBuild.fullDisplayName}\n${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}\"" 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}\""
} }
} }
failure { failure {
script { script {
def message = "❌Deploy thất bại: FRONTEND - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME}, ${currentBuild.fullDisplayName}\n${env.BUILD_URL}" def message = "❌Deploy thất bại: FRONTEND - Môi trường ${params.ENV} - Dự án ${env.PROJECT_NAME} - Portal_Name ${params.PORTAL_NAME}, ${currentBuild.fullDisplayName}\n${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}\"" 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}\""
} }
} }