Thienvv - sua cd backend

This commit is contained in:
thienqb123456
2025-03-05 18:33:19 +07:00
parent 5388c2ca6f
commit 35a3d78ef1
2 changed files with 39 additions and 23 deletions
+15 -9
View File
@@ -17,14 +17,26 @@ pipeline {
ANSIBLE_SSH_CONNECTION = 'root@103.166.183.172 -p 24700' 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_PLAYBOOK_PATH = 'playbooks/backend/deploy_acp_backend.yml'
ANSIBLE_PLAYBOOK_PATH = 'playbooks/deploy_be.yml'
TELEGRAM_CHAT_ID = -4678013464 TELEGRAM_CHAT_ID = -4678013464
TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN') TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN')
} }
stages { stages {
stage('Set up') {
steps {
script {
if (params.ENV == 'uat') {
env.ANSIBLE_INVENTORY_PATH = 'inventory/uat/hosts.ini'
} else if (params.ENV == 'production') {
env.ANSIBLE_INVENTORY_PATH = 'inventory/production/hosts.ini'
}
echo "ANSIBLE_INVENTORY_PATH is set to: ${env.ANSIBLE_INVENTORY_PATH}"
}
}
}
stage('Retrieve Artifact Metadata From CI Job') { stage('Retrieve Artifact Metadata From CI Job') {
steps { steps {
script { script {
@@ -63,8 +75,6 @@ pipeline {
env.ANSIBLE_FOLDER_PATH, env.ANSIBLE_FOLDER_PATH,
env.ANSIBLE_INVENTORY_PATH, env.ANSIBLE_INVENTORY_PATH,
env.ANSIBLE_PLAYBOOK_PATH, env.ANSIBLE_PLAYBOOK_PATH,
params.ENV,
env.PROJECT_NAME,
env.NEXUS_URL, env.NEXUS_URL,
env.NEXUS_ARTIFACT_NAME, env.NEXUS_ARTIFACT_NAME,
env.NEXUS_CREDENTIALS_USR, env.NEXUS_CREDENTIALS_USR,
@@ -188,8 +198,6 @@ def triggerAnsible(
String ansibleansibleFolderPath, String ansibleansibleFolderPath,
String inventoryPath, String inventoryPath,
String playbookPath, String playbookPath,
String deployENV,
String projectName,
String nexusUrl, String nexusUrl,
String nexusArtifactName, String nexusArtifactName,
String nexusUsername, String nexusUsername,
@@ -201,9 +209,7 @@ def triggerAnsible(
ssh ${sshAnsibleConnection} " ssh ${sshAnsibleConnection} "
cd ${ansibleansibleFolderPath} && cd ${ansibleansibleFolderPath} &&
ansible-playbook -i ${inventoryPath} ${playbookPath} \\ ansible-playbook -i ${inventoryPath} ${playbookPath} \\
-e 'deploy_env=${deployENV} \\ -e 'nexus_url=${nexusUrl} \\
project_name=${projectName} \\
nexus_url=${nexusUrl} \\
artifact_name=${nexusArtifactName} \\ artifact_name=${nexusArtifactName} \\
nexus_username=${nexusUsername} \\ nexus_username=${nexusUsername} \\
nexus_password=${nexusPassword}' -vvvv nexus_password=${nexusPassword}' -vvvv
+24 -14
View File
@@ -17,17 +17,36 @@ pipeline {
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 = 'v3'
ANSIBLE_FOLDER_PATH = '/srv/ansible_v2' ANSIBLE_FOLDER_PATH = '/srv/ansible_v3'
ANSIBLE_INVENTORY_PATH = "inventory/${params.ENV}.ini"
ANSIBLE_PLAYBOOK_PATH = 'playbooks/deploy_be_portal.yml'
TELEGRAM_CHAT_ID = -4678013464 TELEGRAM_CHAT_ID = -4678013464
TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN') TELEGRAM_BOT_TOKEN = credentials('TELEGRAM_BOT_TOKEN')
} }
stages { stages {
stage('Set up') {
steps {
script {
if (params.ENV == 'uat') {
env.ANSIBLE_INVENTORY_PATH = 'inventory/uat/hosts.ini'
} else if (params.ENV == 'production') {
env.ANSIBLE_INVENTORY_PATH = 'inventory/production/hosts.ini'
}
echo "ANSIBLE_INVENTORY_PATH is set to: ${env.ANSIBLE_INVENTORY_PATH}"
if (params.PORTAL_NAME == 'ktdt') {
env.ANSIBLE_PLAYBOOK_PATH = 'playbooks/backend/deploy_ktdt_portal_backend.yml'
} else if (params.PORTAL_NAME == 'hnt') {
env.ANSIBLE_PLAYBOOK_PATH = 'playbooks/backend/deploy_hnt_portal_backend.yml'
}
echo "ANSIBLE_PLAYBOOK_PATH is set to: ${env.ANSIBLE_PLAYBOOK_PATH}"
}
}
}
stage('Retrieve Artifact From CI Job') { stage('Retrieve Artifact From CI Job') {
steps { steps {
script { script {
@@ -66,9 +85,6 @@ pipeline {
env.ANSIBLE_FOLDER_PATH, env.ANSIBLE_FOLDER_PATH,
env.ANSIBLE_INVENTORY_PATH, env.ANSIBLE_INVENTORY_PATH,
env.ANSIBLE_PLAYBOOK_PATH, env.ANSIBLE_PLAYBOOK_PATH,
params.ENV,
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,
@@ -191,9 +207,6 @@ def triggerAnsible(
String ansibleansibleFolderPath, String ansibleansibleFolderPath,
String inventoryPath, String inventoryPath,
String playbookPath, String playbookPath,
String deployENV,
String projectName,
String portalName,
String nexusUrl, String nexusUrl,
String nexusArtifactName, String nexusArtifactName,
String nexusUsername, String nexusUsername,
@@ -205,10 +218,7 @@ def triggerAnsible(
ssh ${sshAnsibleConnection} " ssh ${sshAnsibleConnection} "
cd ${ansibleansibleFolderPath} && cd ${ansibleansibleFolderPath} &&
ansible-playbook -i ${inventoryPath} ${playbookPath} \\ ansible-playbook -i ${inventoryPath} ${playbookPath} \\
-e 'deploy_env=${deployENV} \\ -e 'nexus_url=${nexusUrl} \\
project_name=${projectName} \\
portal_name=${portalName} \\
nexus_url=${nexusUrl} \\
artifact_name=${nexusArtifactName} \\ artifact_name=${nexusArtifactName} \\
nexus_username=${nexusUsername} \\ nexus_username=${nexusUsername} \\
nexus_password=${nexusPassword}' -vvvv nexus_password=${nexusPassword}' -vvvv