use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.
the class BuildExecuteService method insertLog.
/**
* 插入记录
*/
private String insertLog(BuildExtraModule buildExtraModule, TaskData taskData) {
BuildInfoModel buildInfoModel = taskData.buildInfoModel;
buildExtraModule.updateValue(buildInfoModel);
BuildHistoryLog buildHistoryLog = new BuildHistoryLog();
// 更新其他配置字段
// buildHistoryLog.fillLogValue(buildExtraModule);
buildHistoryLog.setTriggerBuildType(taskData.triggerBuildType);
//
buildHistoryLog.setBuildNumberId(buildInfoModel.getBuildId());
buildHistoryLog.setBuildName(buildInfoModel.getName());
buildHistoryLog.setBuildDataId(buildInfoModel.getId());
buildHistoryLog.setWorkspaceId(buildInfoModel.getWorkspaceId());
buildHistoryLog.setResultDirFile(buildInfoModel.getResultDirFile());
buildHistoryLog.setReleaseMethod(buildExtraModule.getReleaseMethod());
//
buildHistoryLog.setStatus(BuildStatus.Ing.getCode());
buildHistoryLog.setStartTime(SystemClock.now());
buildHistoryLog.setBuildRemark(taskData.buildRemark);
buildHistoryLog.setExtraData(buildInfoModel.getExtraData());
dbBuildHistoryLogService.insert(buildHistoryLog);
//
buildService.updateStatus(buildHistoryLog.getBuildDataId(), BuildStatus.Ing);
return buildHistoryLog.getId();
}
use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.
the class BuildInfoController method cleanSource.
/**
* 清除构建信息
*
* @param id 构建ID
* @return json
*/
@PostMapping(value = "/build/clean-source", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EXECUTE)
public String cleanSource(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据id") String id) {
// 查询构建信息
BuildInfoModel buildInfoModel = buildInfoService.getByKey(id, getRequest());
Objects.requireNonNull(buildInfoModel, "没有对应数据");
File source = BuildUtil.getSourceById(buildInfoModel.getId());
// 快速删除
boolean fastDel = CommandUtil.systemFastDel(source);
//
Assert.state(!fastDel, "删除文件失败,请检查");
return JsonMessage.getString(200, "清理成功");
}
use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.
the class BuildInfoController method delete.
/**
* 删除构建信息
*
* @param id 构建ID
* @return json
*/
@PostMapping(value = "/build/delete", produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.DEL)
public String delete(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据id") String id) {
// 查询构建信息
HttpServletRequest request = getRequest();
BuildInfoModel buildInfoModel = buildInfoService.getByKey(id, request);
Objects.requireNonNull(buildInfoModel, "没有对应数据");
//
String e = buildExecuteService.checkStatus(buildInfoModel.getStatus());
Assert.isNull(e, () -> e);
// 删除构建历史
dbBuildHistoryLogService.delByWorkspace(request, entity -> entity.set("buildDataId", buildInfoModel.getId()));
// 删除构建信息文件
File file = BuildUtil.getBuildDataFile(buildInfoModel.getId());
// 快速删除
boolean fastDel = CommandUtil.systemFastDel(file);
//
Assert.state(!fastDel, "清理历史构建产物失败,已经重新尝试");
// 删除构建信息数据
buildInfoService.delByKey(buildInfoModel.getId(), request);
return JsonMessage.getString(200, "清理历史构建产物成功");
}
use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.
the class BuildInfoManageController method getNowLog.
/**
* 获取构建的日志
*
* @param id id
* @param buildId 构建编号
* @param line 需要获取的行号
* @return json
*/
@RequestMapping(value = "/build/manage/get-now-log", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getNowLog(@ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "没有数据") String id, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "没有buildId") int buildId, @ValidatorItem(value = ValidatorRule.POSITIVE_INTEGER, msg = "line") int line) {
BuildInfoModel item = buildInfoService.getByKey(id, getRequest());
Assert.notNull(item, "没有对应数据");
Assert.state(buildId <= item.getBuildId(), "还没有对应的构建记录");
BuildHistoryLog buildHistoryLog = new BuildHistoryLog();
buildHistoryLog.setBuildDataId(id);
buildHistoryLog.setBuildNumberId(buildId);
BuildHistoryLog queryByBean = dbBuildHistoryLogService.queryByBean(buildHistoryLog);
Assert.notNull(queryByBean, "没有对应的构建历史");
File file = BuildUtil.getLogFile(item.getId(), buildId);
Assert.state(FileUtil.isFile(file), "日志文件错误");
if (!file.exists()) {
if (buildId == item.getBuildId()) {
return JsonMessage.getString(201, "还没有日志文件");
}
return JsonMessage.getString(300, "日志文件不存在");
}
JSONObject data = FileUtils.readLogFile(file, line);
// 运行中
Integer status = queryByBean.getStatus();
data.put("run", status == BuildStatus.Ing.getCode() || status == BuildStatus.PubIng.getCode());
// 构建中
data.put("buildRun", status == BuildStatus.Ing.getCode());
return JsonMessage.getString(200, "ok", data);
}
use of io.jpom.model.data.BuildInfoModel in project Jpom by dromara.
the class BuildTriggerApiController method trigger2.
/**
* 构建触发器
*
* @param id 构建ID
* @param token 构建的token
* @param delay 延迟时间(单位秒)
* @return json
*/
@RequestMapping(value = ServerOpenApi.BUILD_TRIGGER_BUILD2, produces = MediaType.APPLICATION_JSON_VALUE)
public String trigger2(@PathVariable String id, @PathVariable String token, String delay, String buildRemark) {
BuildInfoModel item = buildInfoService.getByKey(id);
Assert.notNull(item, "没有对应数据");
UserModel userModel = this.getByUrlToken(token);
//
Assert.notNull(userModel, "没有对应数据:-1");
Assert.state(StrUtil.equals(token, item.getTriggerToken()), "触发token错误,或者已经失效");
BaseServerController.resetInfo(userModel);
JsonMessage<Integer> start = buildExecuteService.start(id, userModel, Convert.toInt(delay, 0), 1, buildRemark);
return start.toString();
}
Aggregations