Browse Source

更新 BuildService 中的通知, 发送通知的时机时应用构建失败, 或应用只构建(不部署)

reghao 4 weeks ago
parent
commit
35dfba46e8

+ 7 - 2
mgr/src/main/java/cn/reghao/devops/mgr/ops/builder/service/BuildService.java

@@ -106,8 +106,7 @@ public class BuildService {
                         deployApp.deploy(buildId);
                         ctx.log(">>> [Step 6] 部署请求已提交。");
                     } else {
-                        AppBuilding appBuilding = buildLogService.getAppBuilding(appId);
-                        buildDeployNotify.buildNotify(appBuilding);
+                        sendNotify(appId);
                     }
                 } catch (Exception e) {
                     // 核心设计:一旦任何一步抛出异常,立即进入这里
@@ -116,6 +115,7 @@ public class BuildService {
                     ctx.log("!!! [Pipeline] 任务失败,原因: " + errorMsg + System.lineSeparator() + stackTrace);
                     // 这里更新数据库状态为 FAILURE
                     buildLogService.updateMainStatus(ctx, StepStatus.FAILURE.name());
+                    sendNotify(appId);
                 }
             } catch (Exception e) {
                 throw new RuntimeException(e);
@@ -123,6 +123,11 @@ public class BuildService {
         });
     }
 
+    private void sendNotify(String appId) {
+        AppBuilding appBuilding = buildLogService.getAppBuilding(appId);
+        buildDeployNotify.buildNotify(appBuilding);
+    }
+
     private void runStep(PipelineContext ctx, String stepName, StepExecutor executor) {
         try {
             ctx.updateStep(stepName, StepStatus.RUNNING.name(), null);