Skip to content

Commit

Permalink
pre commit 2.10.3
Browse files Browse the repository at this point in the history
  • Loading branch information
bwcx-jzy committed Dec 22, 2022
1 parent c26094a commit ad5dcde
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 70 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

## 2.10.3 (2022-12-22)

### 🐣 新增功能

1. 【server】新增 在线构建新增 `packageFile` 流程 编译 webhook 或者事件脚本调用

### 🐞 解决BUG、优化功能

1. 【server】修复 快速导入节点工作空间id `undefined`
2. 【server】修复 本地运行脚本默认找不到的情况
3. 【agent】优化 项目控制台日志文件默认编码格式判断系统 windows 默认 GBK,其他默认 UTF-8
(感谢 [@gf_666](https://gitee.com/gf_666) [Gitee issues I66ZZZ](https://gitee.com/dromara/Jpom/issues/I66ZZZ)
4. 【server】优化 在线构建 ssh 清空产物异常不标记发布异常

### ⚠️ 注意

Expand Down
45 changes: 22 additions & 23 deletions modules/server/src/main/java/io/jpom/build/BuildExecuteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -719,30 +719,24 @@ private boolean executeCommand() {
*
* @return false 执行需要结束
*/
private boolean packageRelease() {
private boolean release() {
BuildInfoModel buildInfoModel = taskData.buildInfoModel;
UserModel userModel = taskData.userModel;
boolean status = packageFile();
if (!status) {
// 没有构建产物,将状态传递到后续流程
return false;
}
if (buildInfoModel.getReleaseMethod() != BuildReleaseMethod.No.getCode()) {
// 发布文件
ReleaseManage releaseManage = ReleaseManage.builder()
.buildNumberId(buildInfoModel.getBuildId())
.buildExtraModule(buildExtraModule)
.userModel(userModel)
.logId(logId)
.buildEnv(buildEnv)
.buildExecuteService(buildExecuteService)
.logRecorder(logRecorder).build();
releaseManage.start();
} else {
//
buildExecuteService.updateStatus(buildInfoModel.getId(), logId, BuildStatus.Success);

// 发布文件
ReleaseManage releaseManage = ReleaseManage.builder()
.buildNumberId(buildInfoModel.getBuildId())
.buildExtraModule(buildExtraModule)
.userModel(userModel)
.logId(logId)
.buildEnv(buildEnv)
.buildExecuteService(buildExecuteService)
.logRecorder(logRecorder).build();
try {
return releaseManage.start();
} catch (Exception e) {
throw Lombok.sneakyThrow(e);
}
return true;
}

/**
Expand All @@ -751,7 +745,11 @@ private boolean packageRelease() {
* @return 流程执行是否成功
*/
private boolean finish() {
buildExecuteService.updateLastCommitId(taskData.buildInfoModel.getId(), taskData.repositoryLastCommitId);
BuildInfoModel buildInfoModel1 = taskData.buildInfoModel;
buildExecuteService.updateLastCommitId(buildInfoModel1.getId(), taskData.repositoryLastCommitId);
//
BuildStatus buildStatus = buildInfoModel1.getReleaseMethod() != BuildReleaseMethod.No.getCode() ? BuildStatus.PubSuccess : BuildStatus.Success;
buildExecuteService.updateStatus(buildInfoModel1.getId(), this.logId, buildStatus);
return true;
}

Expand All @@ -764,7 +762,8 @@ public void run() {
suppliers.put("startReady", BuildInfoManage.this::startReady);
suppliers.put("pull", BuildInfoManage.this::pull);
suppliers.put("executeCommand", BuildInfoManage.this::executeCommand);
suppliers.put("release", BuildInfoManage.this::packageRelease);
suppliers.put("packageFile", BuildInfoManage.this::packageFile);
suppliers.put("release", BuildInfoManage.this::release);
suppliers.put("finish", BuildInfoManage.this::finish);
// 依次执行流程,发生异常结束整个流程
String processName = StrUtil.EMPTY;
Expand Down
87 changes: 40 additions & 47 deletions modules/server/src/main/java/io/jpom/build/ReleaseManage.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,39 +163,38 @@ public void updateStatus(BuildStatus status) {
/**
* 不修改为发布中状态
*/
public void start() {
public boolean start() throws IOException {
init();
updateStatus(BuildStatus.PubIng);
this.updateStatus(BuildStatus.PubIng);
logRecorder.info("start release:" + FileUtil.readableFileSize(FileUtil.size(this.resultFile)));
if (!this.resultFile.exists()) {
logRecorder.info("不存在构建产物");
updateStatus(BuildStatus.PubError);
return;
return false;
}
long time = SystemClock.now();
int releaseMethod = this.buildExtraModule.getReleaseMethod();
logRecorder.info("release method:" + BaseEnum.getDescByCode(BuildReleaseMethod.class, releaseMethod));
try {
if (releaseMethod == BuildReleaseMethod.Outgiving.getCode()) {
//
this.doOutGiving();
} else if (releaseMethod == BuildReleaseMethod.Project.getCode()) {
this.doProject();
} else if (releaseMethod == BuildReleaseMethod.Ssh.getCode()) {
this.doSsh();
} else if (releaseMethod == BuildReleaseMethod.LocalCommand.getCode()) {
this.localCommand();
} else if (releaseMethod == BuildReleaseMethod.DockerImage.getCode()) {
this.doDockerImage();
} else {
logRecorder.info(" 没有实现的发布分发:" + releaseMethod);
}
} catch (Exception e) {
this.pubLog("发布异常", e);
return;

if (releaseMethod == BuildReleaseMethod.Outgiving.getCode()) {
//
this.doOutGiving();
} else if (releaseMethod == BuildReleaseMethod.Project.getCode()) {
this.doProject();
} else if (releaseMethod == BuildReleaseMethod.Ssh.getCode()) {
this.doSsh();
} else if (releaseMethod == BuildReleaseMethod.LocalCommand.getCode()) {
this.localCommand();
} else if (releaseMethod == BuildReleaseMethod.DockerImage.getCode()) {
this.doDockerImage();
} else if (releaseMethod == BuildReleaseMethod.No.getCode()) {
return true;
} else {
logRecorder.info(" 没有实现的发布分发:" + releaseMethod);
return false;
}
logRecorder.info("release complete : " + DateUtil.formatBetween(SystemClock.now() - time, BetweenFormatter.Level.MILLISECOND));
updateStatus(BuildStatus.PubSuccess);

return true;
}


Expand Down Expand Up @@ -297,7 +296,7 @@ private void doDockerImage() {
logRecorder.info("没有可用的 docker server");
return;
}
String dockerBuildArgs = this.buildExtraModule.getDockerBuildArgs();
//String dockerBuildArgs = this.buildExtraModule.getDockerBuildArgs();
for (DockerInfoModel infoModel : dockerInfoModels) {
this.doDockerImage(infoModel, dockerfile, baseDir, dockerTag, this.buildExtraModule);
}
Expand Down Expand Up @@ -342,6 +341,7 @@ private void updateSwarmService(String dockerTag, String swarmId, String service
plugin.execute("updateServiceImage", pluginMap);
} catch (Exception e) {
logRecorder.error("更新容器服务调用容器异常", e);
throw Lombok.sneakyThrow(e);
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ private void localCommand() {
/**
* ssh 发布
*/
private void doSsh() {
private void doSsh() throws IOException {
String releaseMethodDataId = this.buildExtraModule.getReleaseMethodDataId();
SshService sshService = SpringUtil.getBean(SshService.class);
List<String> strings = StrUtil.splitTrim(releaseMethodDataId, StrUtil.COMMA);
Expand All @@ -413,7 +413,7 @@ private void doSsh() {
}
}

private void doSsh(SshModel item, SshService sshService) {
private void doSsh(SshModel item, SshService sshService) throws IOException {
Session session = SshService.getSessionByModel(item);
try {
String releasePath = this.buildExtraModule.getReleasePath();
Expand All @@ -429,10 +429,12 @@ private void doSsh(SshModel item, SshService sshService) {
String normalizePath = FileUtil.normalize(prefix + StrUtil.SLASH + releasePath);
if (this.buildExtraModule.isClearOld()) {
try {
sftp.delDir(normalizePath);
if (sftp.exist(normalizePath)) {
sftp.delDir(normalizePath);
}
} catch (Exception e) {
if (!StrUtil.startWithIgnoreCase(e.getMessage(), "No such file")) {
this.pubLog("清除构建产物失败", e);
logRecorder.error("清除构建产物失败", e);
}
}
}
Expand All @@ -454,12 +456,8 @@ private void doSsh(SshModel item, SshService sshService) {
this.formatCommand(commands);
//
logRecorder.info("{} {} start exec", DateUtil.now(), item.getName());
try {
String s = sshService.exec(item, commands);
logRecorder.info(s);
} catch (Exception e) {
this.pubLog(item.getName() + " 执行异常", e);
}
String s = sshService.exec(item, commands);
logRecorder.info(s);
}

/**
Expand Down Expand Up @@ -588,24 +586,19 @@ private void doOutGiving() {
logRecorder.info("开始执行分发包啦,请到分发中查看当前状态");
}


/**
* 发布异常日志
*
* @param title 描述
* @param throwable 异常
*/
private void pubLog(String title, Throwable throwable) {
logRecorder.error(title, throwable);
this.updateStatus(BuildStatus.PubError);
}

@Override
public void run() {
try {
this.start();
boolean start = this.start();
if (start) {
this.updateStatus(BuildStatus.PubSuccess);
} else {
this.updateStatus(BuildStatus.PubError);
}
} catch (Exception e) {
log.error("执行发布异常", e);
logRecorder.error("执行发布异常", e);
this.updateStatus(BuildStatus.PubError);
}
}
}

0 comments on commit ad5dcde

Please sign in to comment.