前端nuxt在jenkins部署
1: 在jenkins上拉代码,写.env,npm build, 生成压缩包
#!/bin/bash
##判断是否存在备份用的nuxt目录##
cd /home/deployer/nuxt_backup/
if [[ ! -d nuxt ]];then
echo "the document is not exsit"
mkdir -p /home/deployer/nuxt_backup/nuxt/
else
echo "the document is exsit"
fi
cd /var/lib/jenkins/workspace/iVideoForce-frontend-Staging
git checkout .
if [ $? -ne 0 ]; then
echo "============================failed=================================="
exit 1
else
echo "===========================succeed=================================="
fi
git checkout staging
if [ $? -ne 0 ]; then
echo "============================failed=================================="
exit 1
else
echo "===========================succeed=================================="
fi
git pull
if [ $? -ne 0 ]; then
echo "============================failed=================================="
exit 1
else
echo "===========================succeed=================================="
fi
npm install
if [ $? -ne 0 ]; then
echo "============================failed=================================="
exit 1
else
echo "===========================succeed=================================="
fi
#cp /home/deployer/env/.env.ivf .env
cat > .env << EOF
API_ENDPOINT=https://mpace-xxxx.ivideocloud.cn
API_KEY=asfssxxxxxxx
API_SECRET=dsdsdssddsssd
PLATFORM_NAME=iVideoForce
PLATFORM_LOGO=/logo.png
FAVICON=/favicon.png
OSS_BUCKET=staging
OSS_REGION=oss-cn-shanghai
OSS_ACCESS_KEY_ID=XXXXXXXDSDDD
OSS_ACCESS_KEY_SECRET=XXXXXXXDddddSDDD
COPYRIGHT=Copyright © 2021 iVideoForce.
VERSION=V1.1
MARKETPLACE_URL=https://ivf.xxxxx.cn/marketplace
FLASHSITE_PREVIEW_URL=https://cdn.xxxxx.cn/mediaspace/theme
EOF
npm run build
if [ $? -ne 0 ]; then
echo "============================failed=================================="
exit 1
else
echo "===========================succeed=================================="
fi
tar -zcf nuxt.tar.gz .nuxt .env static package.json nuxt.config.js
if [ $? -ne 0 ]; then
echo "============================failed=================================="
exit 1
else
echo "===========================succeed=================================="
fi
#rsync -ravO –delete nuxt.tar.gz jenkins170:/home/deployer/testjenkins/
#scp nuxt.tar.gz jenkins170:/var/www/html/staging/ivf.ivideocloud.cn/ivf-platform/
cp nuxt.tar.gz /home/deployer/nuxt_backup/nuxt/`date +%Y%m%d%H%M`.tar.gz
if [ $? -ne 0 ]; then
echo "============================failed=================================="
exit 1
else
echo "===========================succeed=================================="
fi
dir=/home/deployer/nuxt_backup/nuxt/
count=`ls $dir | wc -l`
MAX_RELEASE=10
while [ $count -gt $MAX_RELEASE ]
do
oldest=`ls -t $dir | tail -1`
rm -rf $dir/$oldest
count=`ls $dir | wc -l`
done
2:在测试服
cd /var/www/html/staging/ivf.ivideocloud.cn/
tar -zxf nuxt.tar.gz
npm install
pm2 reload cctv-platform
rm -rf nuxt.tar.gz