自动化,压缩前端工程代码使用ftp上传到服务器,ssh登录服务器,解压上传的压缩代码
接口:
//上传代码到目标服务器
const uploadCode = (req, res) => {
const { buildPath, targetPath } = req.body
const buildBat =
`
echo unzip start
cd /temp/zip
7z x /temp/zip/build.tar -o/temp/unzip -y
xcopy \\temp\\unzip\\build ${targetPath} /Y /E
echo success
`
//创建用于解压的批处理文件
fs.writeFileSync('/temp/zip/build.bat', buildBat, { encoding: 'utf8' }, (err) => {})
//上传build压缩包到服务器
spawn.sync(`./light/jenkins/upload.bat ${buildPath} ${targetPath}`, [], {
stdio: 'inherit'
})
res.send({
state: 1,
data: {
buildPath,
targetPath
},
message: '成功'
})
}
upload.bat:
echo %0 %1 %2
7z.exe a \temp\zip\build.tar %1
ftp -s:C:\ftp\upload.ftp
ssh Administrator@39.97.238.175 "cd \temp\zip && ls && call .\build.bat"
upload.ftp:
open www.xutongbao.top
root
您的密码
cd temp\zip
put \temp\zip\build.tar
put \temp\zip\build.bat
ls
bye
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步