准备相关软件
jenkins上传需要用到的插件
开始创建一个项目New Item



还没安装插件是这样的


安装完Publish Over SSH, PowerShell后,会多出两个

配置基础信息
- 设置Shell命令工具
查看上面Git的安装目录
$ where git
D:\Program Files\Git\mingw64\bin\git.exe
D:\Program Files\Git\cmd\git.exe


- 设置登录服务器信息
打开路径:Manage Jenkins->Configure System->Publish over SSH设置如下

- 设置部署步骤
点Build Now会创建workspace文件夹,由于之前项目是另外一个文件夹,不在workspace里面
C:\ProgramData\Jenkins\.jenkins\workspace

因此部署思路:先在本地打包成tag.gz包,移动到workspace,然后上传服务器,执行服务器命令,完成解压,移动到部署的网站目录上


、
先删除workspace的发包目录
rm -rf dist
echo "workspace:删除dist"

使用powershell打包移动到jenkins的workspace下

d:
cd D:\project\xxxx-admin
npm run build:test
echo "POWERSHELL:打包完成"
mv .\dist C:\ProgramData\Jenkins\.jenkins\workspace\XXX_TEST\
echo "POWERSHELL:移动完成"
exit 0

压缩文件夹成tar.gz
cd dist
tar -zcvf dist.tar.gz *
echo "SHELL:压缩完成"

设置上传服务器



Transfer Set Source files 这里要说明一下,包括使用Execute Shell, 都是相对workspace的,一般在安装路径这里
C:\ProgramData\Jenkins\.jenkins\workspace\XXX

最后点Build Now测试
网友评论