fix: 清理发布步骤终态提示

This commit is contained in:
湛兮
2026-06-11 22:43:24 +08:00
parent 62a2f933d3
commit 2181fc7389
+46 -8
View File
@@ -1,3 +1,7 @@
/**
* 编排发布单从 Gitea 校验、Jenkins 构建、健康检查到通知归档的状态推进。
* Jenkins 触发与轮询可能跨进程完成,终态写入时必须清理运行态提示。
*/
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { AuditService } from '../audit/audit.service'; import { AuditService } from '../audit/audit.service';
import { AppError } from '../common/errors/app-error'; import { AppError } from '../common/errors/app-error';
@@ -53,7 +57,11 @@ export class DeployExecutionService {
try { try {
currentStep = 'gitea-check'; currentStep = 'gitea-check';
currentRun = await this.completeStep(currentRun.id, currentStep, 'success'); currentRun = await this.completeStep(
currentRun.id,
currentStep,
'success',
);
currentStep = 'jenkins-build'; currentStep = 'jenkins-build';
const jenkinsResult = await this.advanceJenkinsBuild(currentRun, project); const jenkinsResult = await this.advanceJenkinsBuild(currentRun, project);
@@ -65,13 +73,21 @@ export class DeployExecutionService {
} }
currentStep = 'health-check'; currentStep = 'health-check';
currentRun = await this.completeStep(currentRun.id, currentStep, 'success'); currentRun = await this.completeStep(
currentRun.id,
currentStep,
'success',
);
currentStep = 'notify-wecom'; currentStep = 'notify-wecom';
currentRun = await this.advanceNotification(currentRun, 'succeeded'); currentRun = await this.advanceNotification(currentRun, 'succeeded');
currentStep = 'finish-release'; currentStep = 'finish-release';
currentRun = await this.completeStep(currentRun.id, currentStep, 'success'); currentRun = await this.completeStep(
currentRun.id,
currentStep,
'success',
);
currentRun = this.requireRun( currentRun = this.requireRun(
currentRun.id, currentRun.id,
await this.deployRunRepository.updateRun(currentRun.id, { await this.deployRunRepository.updateRun(currentRun.id, {
@@ -102,6 +118,7 @@ export class DeployExecutionService {
currentStep, currentStep,
{ {
status: 'failed', status: 'failed',
message: undefined,
errorSummary: failureSummary, errorSummary: failureSummary,
}, },
)) ?? currentRun; )) ?? currentRun;
@@ -205,7 +222,10 @@ export class DeployExecutionService {
currentRun = this.requireRun( currentRun = this.requireRun(
currentRun.id, currentRun.id,
await this.deployRunRepository.updateRun(currentRun.id, { await this.deployRunRepository.updateRun(currentRun.id, {
status: buildStatus.building || !buildStatus.result ? 'running' : currentRun.status, status:
buildStatus.building || !buildStatus.result
? 'running'
: currentRun.status,
jenkinsBuildNumber: buildStatus.buildNumber, jenkinsBuildNumber: buildStatus.buildNumber,
jenkinsBuildUrl: buildStatus.url, jenkinsBuildUrl: buildStatus.url,
}), }),
@@ -242,7 +262,11 @@ export class DeployExecutionService {
const reason = const reason =
health.message ?? health.message ??
'Jenkins is not configured; simulated build completed.'; 'Jenkins is not configured; simulated build completed.';
const currentRun = await this.completeStep(run.id, 'jenkins-build', 'success'); const currentRun = await this.completeStep(
run.id,
'jenkins-build',
'success',
);
this.auditService.record({ this.auditService.record({
action: 'JENKINS_DRY_RUN_COMPLETED', action: 'JENKINS_DRY_RUN_COMPLETED',
@@ -346,10 +370,22 @@ export class DeployExecutionService {
private async completeSuccessfulJenkinsRun( private async completeSuccessfulJenkinsRun(
run: DeployRunSummary, run: DeployRunSummary,
): Promise<DeployRunSummary> { ): Promise<DeployRunSummary> {
let currentRun = await this.completeStep(run.id, 'jenkins-build', 'success'); let currentRun = await this.completeStep(
currentRun = await this.completeStep(currentRun.id, 'health-check', 'success'); run.id,
'jenkins-build',
'success',
);
currentRun = await this.completeStep(
currentRun.id,
'health-check',
'success',
);
currentRun = await this.advanceNotification(currentRun, 'succeeded'); currentRun = await this.advanceNotification(currentRun, 'succeeded');
currentRun = await this.completeStep(currentRun.id, 'finish-release', 'success'); currentRun = await this.completeStep(
currentRun.id,
'finish-release',
'success',
);
currentRun = this.requireRun( currentRun = this.requireRun(
currentRun.id, currentRun.id,
await this.deployRunRepository.updateRun(currentRun.id, { await this.deployRunRepository.updateRun(currentRun.id, {
@@ -382,6 +418,7 @@ export class DeployExecutionService {
let currentRun = let currentRun =
(await this.deployRunRepository.updateStep(run.id, 'jenkins-build', { (await this.deployRunRepository.updateStep(run.id, 'jenkins-build', {
status: 'failed', status: 'failed',
message: undefined,
errorSummary: failureSummary, errorSummary: failureSummary,
logExcerpt, logExcerpt,
})) ?? run; })) ?? run;
@@ -473,6 +510,7 @@ export class DeployExecutionService {
runId, runId,
await this.deployRunRepository.updateStep(runId, bpmnNodeId, { await this.deployRunRepository.updateStep(runId, bpmnNodeId, {
status, status,
message: undefined,
errorSummary, errorSummary,
}), }),
); );