jenkins自动化部署vue项目
2018-06-11 本文已影响383人
炒面Z
1.在jenkins的docker容器中安装nodeJs
https://www.jianshu.com/p/88cf2c1375ce
2.在docker中运行nginx,第四步中jenkins会把vue项目生成的代码拷贝到/opt/nginx-website/web中
#nginx
docker run \
-p 80:80 \
--restart=always --name=nginx \
-v /opt/nginx/conf.d:/etc/nginx/conf.d \
-v /opt/nginx-website/web:/usr/share/nginx \
-v /etc/timezone:/etc/timezone \
-v /etc/localtime:/etc/localtime \
-d nginx \
3.nginx配置文件,配置文件都在/opt/nginx/conf.d目录下:
server {
listen 80;
charset utf-8;
server_name api.***.cn;
root /usr/share/nginx/website;
index index.html;
location ~ ^/favicon\.ico$ {
root /usr/share/nginx/website;
}
location / { try_files $uri $uri/ /index.html; }
}
4.jenkins中配置vue项目shell脚本
echo $PATH
echo '>>> npm run build'
npm install
npm run build
echo '>>> delete files in /opt/nginx-website/web/website'
sudo rm -r /opt/nginx-website/web/website/*
echo '>>> copy dist/* to /opt/nginx-website/web/website'
sudo cp -r dist/* /opt/nginx-website/web/website
echo '>>> restart nginx-website '
sudo docker restart nginx