|
|
@ -1,26 +1,27 @@ |
|
|
|
var express = require('express'); |
|
|
|
var express = require('express'); |
|
|
|
var router = express.Router(); |
|
|
|
var router = express.Router(); |
|
|
|
const { exec } = require('child_process'); |
|
|
|
|
|
|
|
//web钩子事件
|
|
|
|
//web钩子事件
|
|
|
|
//git@gogs.kirito.cool:panqihua/RiskCloudMock.git push事件
|
|
|
|
//git@gogs.kirito.cool:panqihua/RiskCloudMock.git push事件
|
|
|
|
|
|
|
|
const {spawn} = require('child_process'); |
|
|
|
router.post('/server', function(req, res, next) { |
|
|
|
router.post('/server', function(req, res, next) { |
|
|
|
|
|
|
|
|
|
|
|
const updated_at=req.body.repository.updated_at |
|
|
|
const updated_at=req.body.repository.updated_at |
|
|
|
|
|
|
|
|
|
|
|
const shell='nohup updateRisk RiskCloudMock &' |
|
|
|
console.info('调用自动部署命令') |
|
|
|
// 输出当前目录(不一定是代码所在的目录)下的文件和文件夹
|
|
|
|
const spawnObj = spawn('updateRisk', ['RiskCloudMock'], {encoding: 'utf-8'}); |
|
|
|
console.log(`开始执行shell:${shell}`) |
|
|
|
spawnObj.stdout.on('data', function(chunk) { |
|
|
|
exec(shell, (err, stdout, stderr) => { |
|
|
|
console.log(chunk.toString()); |
|
|
|
if(err) { |
|
|
|
}); |
|
|
|
console.log(err) |
|
|
|
spawnObj.stderr.on('data', (data) => { |
|
|
|
res.json({message:'自动部署服务端失败'}) |
|
|
|
console.log(data); |
|
|
|
}else { |
|
|
|
}); |
|
|
|
console.log(stdout) |
|
|
|
spawnObj.on('close', function(code) { |
|
|
|
res.json({message: `开始自动部署服务端,版本号:${updated_at}`}) |
|
|
|
console.log('close code : ' + code); |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
spawnObj.on('exit', (code) => { |
|
|
|
|
|
|
|
console.log('exit code : ' + code); |
|
|
|
|
|
|
|
res.json({message: `仓库代码${req.query.name}部署成功`}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|