博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jenkins 编译 vue 项目、远程发布项目 脚本
阅读量:5894 次
发布时间:2019-06-19

本文共 8963 字,大约阅读时间需要 29 分钟。

  hot3.png

第三版命令(升级)

#!/bin/bashecho '''######################################################## $Name             : buildPro.sh	                                # $Version          : v3.0                                 # $Function         : release/on-line for jboss Script # $Author           : Mad Dragon# $Create Date      : 2019-1-5 16:09:42# $email            : 395548460@qq.com# $Description      : 通用项目部署 shellscript 脚本#######################################################'''set -e# start: config...echo "==================start: 项目信息========================="# 需要远程上传的服务器# serviceNameLst="root@192.168.2.150 root@172.30.34.210"serviceNameLst=$1echo "serviceNameLst $serviceNameLst"# workSpacePath 工作区间地址workSpacePath="${WORKSPACE}"# workSpaceName 项目名# 一般为项目名: 驼峰写法 customer-center-app ==》customerCenterAppworkSpaceName="${JOB_BASE_NAME}"deployProHome="home"deployProConfig="proconfig"deployProCommon="common"deployProPath="/$deployProHome/$deployProConfig/$deployProCommon"deployProName="deployPro.sh"# 项目文件压缩包名 默认 dist.tar.gzresourceName="dist.tar.gz"# 项目部署地址projectPath="/home/project/${workSpaceName}"# 临时文件存放地址 从远程拉取的项目文件存放的地方transferPath="/home/project/transfer/${workSpaceName}"# 备份 项目文件压缩包名filename="${JOB_NAME}_${BUILD_ID}.tar.gz"# 备份 项目文件存放地址backPath="/home/back/${JOB_BASE_NAME}"# end: config...nodeV=$(node -v)npmV=$(npm -v)echo """#######################################################变量配置:#   serviceNameLst  : $serviceNameLst#   workSpacePath   : $workSpacePath#   workSpaceName   : $workSpaceName#   deployProHome   : $deployProHome#   deployProConfig : $deployProConfig#   deployProCommon : $deployProCommon#   deployProPath   : $deployProPath#   deployProName   : $deployProName#   resourceName    : $resourceName#   projectPath     : $projectPath#   transferPath    : $transferPath#   filename        : $filename#   backPath        : $backPath    系统环境:#   node 版本       : $nodeV#   npm 版本        : $npmV#######################################################"""# start: function...........printf "\n\n"printf "\n\n"echo "==================start: 项目编译========================="printf "\n\n"echo "001、更新依赖 install         ====》"npm installprintf "\n\n"echo "002、编译 build               ====》"npm run buildprintf "\n\n"echo "003、压缩文件 $resourceName   ====》"cd disttar -zcf $resourceName *printf "\n\n"mkdir -p $projectPathecho "004、创建 $projectPath        ====》"printf "\n\n"rm -rf $projectPath/$resourceNamemv $resourceName $projectPath/echo "005、移动文件 $projectPath/$resourceName         ====》"printf "\n\n"echo "006、目录结构                 ====》"ls $projectPathprintf "\n\n"echo "==================start: 远程上传文件========================="echo "007、start:远程上传文件...                        ====》"printf "\n\n"for serviceName in $serviceNameLstdo    echo "serviceName: $serviceName "ssh -t $serviceName<
"ip addprintf "\n\n"mkdir -p $transferPathecho " [debug]:创建 transferPath:$transferPath"mkdir -p $deployProPathecho " [debug]:创建 deployProPath:$deployProPath"mkdir -p $projectPathecho " [debug]:创建 projectPath:$projectPath"mkdir -p $backPathecho " [debug]:创建 backPath:$backPath"printf "\n\n"EOF scp -r "$projectPath/$resourceName" "$serviceName:$transferPath" echo " [debug]:上传 $projectPath/$resourceName 到 $serviceName:$transferPath 成功!" printf "\n\n"doneprintf "\n\n"echo "end:远程上传文件..."printf "\n\n"echo "撒花结束 *★,°*:.☆( ̄▽ ̄)/$:*.°★* 。"printf "\n\n"echo "==================start:项目部署========================="for serviceName in $serviceNameLstdo ssh -t $serviceName<
"ip addprintf "\n\n"rm -rf $projectPath/* echo " [debug]:删除 $projectPath/* 旧文件 成功" printf "\n\n"ls $projectPathprintf "\n\n"mv "$transferPath/$resourceName" "$projectPath/"echo " [debug]:移动 压缩包文件 $transferPath/$resourceName 到 $projectPath 成功" printf "\n\n"cd $projectPath/pwdprintf "\n\n"tar -zxf $resourceNameecho " [debug]:将 $projectPath/$resourceName 解压 $projectPath 成功" printf "\n\n"mv "$projectPath/$resourceName" $backPath/$filenameecho " [debug]:将文件 $projectPath/$resourceName 备份到 $backPath/$filename 成功"printf "\n\n"EOFdone# ----------------------------------------------

第二版命令(升级)

1、本机shell操作

#!/bin/bashset -e# author:Mad Dragon# email:395548460@qq.com# 通用项目部署 shellscript 脚本echo "==================start build project========================="# start: config...# 需要远程上传的服务器serviceNameLst="root@192.168.2.150 root@172.30.34.210"echo "serviceNameLst $serviceNameLst"# workSpacePath 工作区间地址workSpacePath="${WORKSPACE}"# workSpaceName 项目名# 一般为项目名: 驼峰写法 customer-center-app ==》customerCenterAppworkSpaceName="${JOB_BASE_NAME}"echo "workSpaceName $workSpaceName"deployProHome="home"echo "deployProHome $deployProHome"deployProConfig="proconfig"echo "deployProConfig $deployProConfig"deployProCommon="common"echo "deployProCommon $deployProCommon"deployProPath="/$deployProHome/$deployProConfig/$deployProCommon"echo "deployProPath $deployProPath"deployProName="deployPro.sh"echo "deployProName $deployProName"# 项目文件压缩包名 默认 dist.tar.gzresourceName="dist.tar.gz"echo "resourceName $resourceName"# 项目部署地址projectPath="/home/project/${workSpaceName}"echo "projectPath $projectPath"# 临时文件存放地址 从远程拉取的项目文件存放的地方transferPath="/home/project/transfer/${workSpaceName}"echo "transferPath $transferPath"# 备份 项目文件压缩包名filename="${JOB_NAME}_${BUILD_ID}.tar.gz"echo "filename $filename" # 备份 项目文件存放地址backPath="/home/back/${JOB_BASE_NAME}"echo "backPath $backPath" # end: config...# start: function...........echo "proPath: $projectPath"echo "node 版本:"node -vecho "npm 版本:"npm -vprintf "\n\n"echo "更新依赖 install"npm installprintf "\n\n"echo "编译 build"npm run buildprintf "\n\n"echo "压缩文件 $resourceName"cd disttar -zcf $resourceName *printf "\n\n"mkdir -p $projectPathecho "创建 $projectPath"printf "\n\n"rm -rf $projectPath/$resourceNamemv $resourceName $projectPath/echo "移动文件 $projectPath/$resourceName"printf "\n\n"echo "目录结构"ls $projectPathprintf "\n\n"echo "start:远程上传文件..."printf "\n\n"for serviceName in $serviceNameLstdo    echo "serviceName: $serviceName "ssh -t $serviceName<

第一版命令

1、本机shell 操作

o "==================start build project========================="# start: config...# 需要远程上传的服务器serviceName1="root@192.168.2.150"# workSpaceName 工作区间名   # 一般为项目名: 驼峰写法 customer-center-app ==》customerCenterAppworkSpaceName="${JOB_BASE_NAME}"# 项目文件压缩包名 默认 dist.tar.gzresourceName="dist.tar.gz"# 项目部署地址projectPath="/home/project/${workSpaceName}"# 临时文件存放地址 从远程拉取的项目文件存放的地方transferPath="/home/project/transfer/${workSpaceName}"# end: config...echo 'proPath:'echo $projectPathecho 'node 版本:'node -vecho 'npm 版本:'npm -vecho '更新依赖 install'npm installecho '编译 build'npm run buildecho '压缩文件'cd disttar -zcf $resourceName *echo '移动文件 $projectPath/$resourceName'echo '判断文件是否存在'if test -e $projectPaththen    echo '文件已存在! ${projectPath}'else    echo '文件不存在! ${projectPath}'    mkdir $projectPathfirm -rf $projectPath/$resourceNamemv $resourceName $projectPath/echo '目录结构'ls $projectPathecho 'start:远程上传文件...'echo '判断文件是否存在'if ssh $serviceName1 test -e $transferPaththen    echo '文件已存在! ${serviceName1}:${transferPath}'else    echo '文件不存在! ${serviceName1}:${transferPath}'    ssh -t $serviceName1 mkdir $transferPath/fiscp -r $projectPath/$resourceName $serviceName1:$transferPath/echo 'end:远程上传文件...'echo '撒花结束 *★,°*:.☆( ̄▽ ̄)/$:*.°★* 。'echo "==================deploy build success========================="# ----------------------------------------------

2、免密登录远程服务器后操作

#!/bin/bashecho "==================start deploy project========================="echo '项目运行服务器。。。。'# start: config...# workSpaceName 工作区间名   # 一般为项目名: 驼峰写法 customer-center-app ==》customerCenterAppworkSpaceName="${JOB_BASE_NAME}"# 项目文件压缩包名 默认 dist.tar.gzresourceName="dist.tar.gz"# 远程项目存放地址originPath="root@172.30.34.188:/home/project/${workSpaceName}"# 临时文件存放地址 从远程拉取的项目文件存放的地方transferPath="/home/project/transfer/${workSpaceName}"# 项目部署地址projectPath="/home/project/${JOB_BASE_NAME}"# 备份 项目文件压缩包名filename="${JOB_NAME}_${BUILD_ID}.tar.gz"# 备份 项目文件存放地址backPath="/home/back/${JOB_BASE_NAME}"# end: config...echo '查看ip'ip add echo '进入项目目录 ${transferPath}' echo '判断文件是否存在'if test -e $transferPaththen    echo '文件已存在! ${transferPath}'else    echo '文件不存在! ${transferPath}'    mkdir $transferPathficd $transferPath/ echo '远程下载文件开始 ${originPath}/${resourceName}'scp -r $originPath/$resourceName $transferPathecho '删除 ${JOB_BASE_NAME}旧文件' echo '判断文件是否存在'if test -e $projectPaththen    echo '文件已存在! ${projectPath}'else    echo '文件不存在! ${projectPath}'    mkdir $projectPathfirm -rf $projectPath/* echo '移动 压缩包文件 到 ${projectPath}' mv dist.tar.gz $projectPath/echo '进入 ${JOB_BASE_NAME} 目录' cd $projectPath/echo '解压 dist.tar.gz' tar -zxf $resourceNameecho '将文件备份到 ${backPath}/${filename}'echo '判断文件是否存在'if test -e $backPaththen    echo '文件已存在! ${backPath}'else    echo '文件不存在! ${backPath}'    mkdir $backPathfimv dist.tar.gz $backPath/$filenameecho "==================deploy project success========================="

转载于:https://my.oschina.net/520wsl/blog/2997382

你可能感兴趣的文章
Java工程师面试必备书单 | 掘金技术征文
查看>>
Android 指纹登录、支付
查看>>
springcloud服务注册与发现(二)
查看>>
[SceneKit专题]6-Scene-Editor场景编辑器
查看>>
记一次跨域问题的解决方案
查看>>
NSNotificationCenter
查看>>
@angular装饰器总结
查看>>
Python 拓展之 *args & **kwargs
查看>>
9-Flink中的Time
查看>>
Python将字符串转为字典最佳实践
查看>>
pandas.loc方法使用详解
查看>>
关于UIButton的UIEdgeInsets属性
查看>>
项目流程
查看>>
Django&Mysql
查看>>
使用Docker构建你的第一个服务
查看>>
sql server(常用)
查看>>
大数据项目实践(四)——之Hive配置
查看>>
js 调试接口
查看>>
Thread类源码解读(1)——如何创建和启动线程
查看>>
vue 实现数字滚动增加效果
查看>>