新增nodejs-email 流水线脚本
This commit is contained in:
@@ -1,64 +1,90 @@
|
||||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
DEPLOY_HOST = '49.51.46.148' // 目标机 IP 或域名
|
||||
DEPLOY_DIR = '/data/tengine/html/lessie_official' // 目标机部署目录
|
||||
}
|
||||
stages {
|
||||
stage('Checkout 代码') {
|
||||
steps {
|
||||
git branch: 'dev', credentialsId: 'fly_gitlab_auth', url: 'http://172.24.16.20/web/scalelink-frontend.git'
|
||||
}
|
||||
agent any
|
||||
|
||||
environment {
|
||||
// CODE_BRANCH = "dev"
|
||||
LOCKHOST_IP = "192.168.70.15"
|
||||
LOCKHOST_PROJECT_PATH = "/root/cdx/scalelink-frontend"
|
||||
WEB_HOST_IP_1 = "43.130.56.138"
|
||||
WEB_HOST_IP_2 = "43.153.21.64"
|
||||
WEB_HOST_PROJECT_PATH = "/data/webapps/lessie_official_web"
|
||||
}
|
||||
stage('Install & Build') {
|
||||
steps {
|
||||
sh """
|
||||
cd ${WORKSPACE}/projects/lessie' &&
|
||||
npm install --frozen-lockfile &&
|
||||
npm run build
|
||||
"""
|
||||
}
|
||||
}
|
||||
stage('同步文件') {
|
||||
steps {
|
||||
// 打包必要文件:.output、package.json、pnpm-lock.yaml
|
||||
# sh '''
|
||||
# rm -rf deploy.tar.gz
|
||||
# tar czf deploy.tar.gz \
|
||||
# .output package.json pnpm-lock.yaml
|
||||
# '''
|
||||
# archiveArtifacts artifacts: 'deploy.tar.gz'
|
||||
}
|
||||
}
|
||||
stage('Deploy to Target') {
|
||||
steps {
|
||||
sshagent([SSH_CRED]) {
|
||||
// 1) 传输压缩包
|
||||
sh """
|
||||
scp deploy.tar.gz ${DEPLOY_USER}@${DEPLOY_HOST}:/tmp/
|
||||
"""
|
||||
// 2) 解压、安装依赖、重启
|
||||
sh """
|
||||
ssh ${DEPLOY_USER}@${DEPLOY_HOST} '
|
||||
mkdir -p ${DEPLOY_DIR} &&
|
||||
tar xzf /tmp/deploy.tar.gz -C ${DEPLOY_DIR} &&
|
||||
cd ${DEPLOY_DIR} &&
|
||||
# 安装生产依赖
|
||||
npm install --production &&
|
||||
# 重启 pm2 服务
|
||||
pm2 reload nuxt-app || pm2 start .output/server/index.mjs --name nuxt-app
|
||||
'
|
||||
"""
|
||||
|
||||
stages {
|
||||
stage('拉取代码') {
|
||||
steps {
|
||||
git branch: "${params.Code_branch}",
|
||||
credentialsId: 'fly_gitlab_auth',
|
||||
url: 'http://172.24.16.20/web/scalelink-frontend.git'
|
||||
}
|
||||
}
|
||||
|
||||
stage('同步到本地机器') {
|
||||
steps {
|
||||
sh """
|
||||
ssh ${LOCKHOST_IP} 'rm -rf ${LOCKHOST_PROJECT_PATH}/*' &&
|
||||
rsync -az ${WORKSPACE}/ ${LOCKHOST_IP}:${LOCKHOST_PROJECT_PATH}/
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('依赖和构建') {
|
||||
steps {
|
||||
sh """
|
||||
ssh ${LOCKHOST_IP} "bash -lc \\"
|
||||
cd ${LOCKHOST_PROJECT_PATH}/projects/lessie &&
|
||||
pnpm install --force && pnpm build &&
|
||||
tar -czf output.tar.gz .output
|
||||
\\""
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('上传产物到机器1') {
|
||||
steps {
|
||||
sh """
|
||||
ssh ${LOCKHOST_IP} "bash -lc \\"
|
||||
scp -r ${LOCKHOST_PROJECT_PATH}/projects/lessie/output.tar.gz ${WEB_HOST_IP_2}:${WEB_HOST_PROJECT_PATH}/
|
||||
\\""
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('启动机器1') {
|
||||
steps {
|
||||
sh """
|
||||
ssh ${WEB_HOST_IP_2} '
|
||||
cd ${WEB_HOST_PROJECT_PATH} && pm2 list &&
|
||||
pm2 delete lessie-official-web --silent || true &&
|
||||
tar -zxf output.tar.gz &&
|
||||
pm2 start .output/server/index.mjs --name lessie-official-web --output ./nuxt-out.log --error ./nuxt-error.log
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('上传产物到机器2') {
|
||||
steps {
|
||||
sh """
|
||||
ssh ${LOCKHOST_IP} "bash -lc \\"
|
||||
scp -r ${LOCKHOST_PROJECT_PATH}/projects/lessie/output.tar.gz ${WEB_HOST_IP_1}:${WEB_HOST_PROJECT_PATH}/
|
||||
\\""
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
stage('启动机器2') {
|
||||
steps {
|
||||
sh """
|
||||
ssh ${WEB_HOST_IP_1} '
|
||||
bash &&
|
||||
cd ${WEB_HOST_PROJECT_PATH} && pm2 list &&
|
||||
pm2 delete lessie-official-web --silent || true &&
|
||||
tar -zxf output.tar.gz &&
|
||||
pm2 start .output/server/index.mjs --name lessie-official-web --output ./nuxt-out.log --error ./nuxt-error.log
|
||||
'
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success {
|
||||
echo '部署成功 🎉'
|
||||
}
|
||||
failure {
|
||||
echo '部署失败,请检查日志 ❌'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user