163 lines
5.0 KiB
Plaintext
163 lines
5.0 KiB
Plaintext
pipeline {
|
|
agent any
|
|
|
|
environment {
|
|
CODE_BRANCH = "dev"
|
|
LOCKHOST_IP = "192.168.70.15"
|
|
LOCKHOST_PROJECT_PATH = "/root/cdx/scalelink-frontend"
|
|
WEB_HOST_IP = "43.130.56.138"
|
|
WEB_HOST_PROJECT_PATH = "/data/webapps/lessie_official_web"
|
|
}
|
|
|
|
stages {
|
|
stage('拉取代码') {
|
|
steps {
|
|
git branch: "${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('上传产物') {
|
|
steps {
|
|
sh """
|
|
ssh ${LOCKHOST_IP} "bash -lc \\"
|
|
scp -r ${LOCKHOST_PROJECT_PATH}/projects/lessie/output.tar.gz ${WEB_HOST_IP}:${WEB_HOST_PROJECT_PATH}/
|
|
\\""
|
|
"""
|
|
}
|
|
}
|
|
|
|
stage('启动') {
|
|
steps {
|
|
sh """
|
|
ssh ${WEB_HOST_IP} '
|
|
cd ${WEB_HOST_PROJECT_PATH} && pm2 list &&
|
|
pm2 delete lessie-official-web &&
|
|
tar -zxf output.tar.gz &&
|
|
pm2 start .output/server/index.mjs --name lessie-official-web --output ./nuxt-out.log --error ./nuxt-error.log
|
|
'
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
# ------------上边是旧的,下边的新的------------------
|
|
|
|
|
|
pipeline {
|
|
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"
|
|
}
|
|
|
|
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 &&
|
|
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 &&
|
|
tar -zxf output.tar.gz &&
|
|
pm2 start .output/server/index.mjs --name lessie-official-web --output ./nuxt-out.log --error ./nuxt-error.log
|
|
'
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|