diff --git a/packages/core/pipeline/src/core/executor.ts b/packages/core/pipeline/src/core/executor.ts index c58ceca9..776a56f7 100644 --- a/packages/core/pipeline/src/core/executor.ts +++ b/packages/core/pipeline/src/core/executor.ts @@ -28,9 +28,10 @@ export class Executor { this.pipelineContext = this.contextFactory.getContext("pipeline", this.pipeline.id); } - async run(runtimeId: any = 0) { + async run(runtimeId: any = 0, triggerType: string) { try { - this.runtime = new RunHistory(runtimeId, this.pipeline); + const trigger = { type: triggerType }; + this.runtime = new RunHistory(runtimeId, trigger, this.pipeline); this.logger.info(`pipeline.${this.pipeline.id} start`); await this.runWithHistory(this.pipeline, "pipeline", async () => { await this.runStages(); @@ -62,7 +63,6 @@ export class Executor { await this.onChanged(this.runtime); return ResultType.success; } catch (e: any) { - this.logger.error(e); this.runtime.error(runnable, e); await this.pipelineContext.set(contextKey, ResultType.error); await this.onChanged(this.runtime); @@ -140,7 +140,7 @@ export class Executor { const define = taskPlugin.getDefine(); //从outputContext读取输入参数 _.forEach(define.input, (item, key) => { - if (item.component?.name === "output-selector") { + if (item.component?.name === "pi-output-selector") { const contextKey = step.input[key]; if (contextKey != null) { step.input[key] = this.runtime.context[contextKey]; diff --git a/packages/core/pipeline/src/core/run-history.ts b/packages/core/pipeline/src/core/run-history.ts index 02c90ff5..63e05d57 100644 --- a/packages/core/pipeline/src/core/run-history.ts +++ b/packages/core/pipeline/src/core/run-history.ts @@ -8,6 +8,9 @@ export type HistoryStatus = { logs: string[]; }; +export type RunTrigger = { + type: string; // user , timer +}; export class RunHistory { id: string; //运行时上下文变量 @@ -19,9 +22,11 @@ export class RunHistory { loggers: { [runnableId: string]: Logger; } = {}; - constructor(runtimeId: any, pipeline: Pipeline) { + trigger: RunTrigger; + constructor(runtimeId: any, trigger: RunTrigger, pipeline: Pipeline) { this.id = runtimeId; this.pipeline = pipeline; + this.trigger = trigger; } start(runnable: Runnable): HistoryResult { @@ -72,7 +77,7 @@ export class RunHistory { message: e.message, }); - this.log(runnable, `执行异常:${e.message}`); + this.logError(runnable, e); } log(runnable: Runnable, text: string) { @@ -80,6 +85,11 @@ export class RunHistory { this.loggers[runnable.id].info(`[${runnable.title}] [${runnable.runnableType}]`, text); } + logError(runnable: Runnable, e: Error) { + // @ts-ignore + this.loggers[runnable.id].error(`[${runnable.title}] [${runnable.runnableType}]`, e); + } + finally(runnable: Runnable) { // } diff --git a/packages/core/pipeline/src/d.ts/pipeline.ts b/packages/core/pipeline/src/d.ts/pipeline.ts index 5f5dd307..a5e9fdd5 100644 --- a/packages/core/pipeline/src/d.ts/pipeline.ts +++ b/packages/core/pipeline/src/d.ts/pipeline.ts @@ -52,6 +52,7 @@ export type Trigger = { id: string; title: string; cron: string; + type: string; }; export type Runnable = { @@ -60,6 +61,9 @@ export type Runnable = { strategy?: RunnableStrategy; runnableType?: string; // pipeline, stage, task , step status?: HistoryResult; + default?: { + [key: string]: any; + }; }; export type Pipeline = Runnable & { diff --git a/packages/core/pipeline/src/plugin/plugins/cert-plugin/index.ts b/packages/core/pipeline/src/plugin/plugins/cert-plugin/index.ts index bd96e3ea..24e2e0f2 100644 --- a/packages/core/pipeline/src/plugin/plugins/cert-plugin/index.ts +++ b/packages/core/pipeline/src/plugin/plugins/cert-plugin/index.ts @@ -23,6 +23,7 @@ export type CertInfo = { vModel: "value", mode: "tags", }, + required: true, col: { span: 24, }, @@ -34,6 +35,7 @@ export type CertInfo = { name: "a-input", vModel: "value", }, + required: true, helper: "请输入邮箱", }, dnsProviderType: { @@ -41,6 +43,7 @@ export type CertInfo = { component: { name: "pi-dns-provider-selector", }, + required: true, helper: "请选择dns解析提供商", }, dnsProviderAccess: { @@ -48,20 +51,20 @@ export type CertInfo = { component: { name: "pi-access-selector", }, + required: true, helper: "请选择dns解析提供商授权", }, renewDays: { title: "更新天数", - value: 20, component: { name: "a-input-number", vModel: "value", }, + required: true, helper: "到期前多少天后更新证书", }, forceUpdate: { title: "强制更新", - value: false, component: { name: "a-switch", vModel: "checked", @@ -69,6 +72,12 @@ export type CertInfo = { helper: "是否强制重新申请证书", }, }, + default: { + input: { + renewDays: 20, + forceUpdate: false, + }, + }, output: { cert: { key: "cert", diff --git a/packages/core/pipeline/src/plugin/plugins/deploy-to-cdn/index.ts b/packages/core/pipeline/src/plugin/plugins/deploy-to-cdn/index.ts index bbce352b..d75a7699 100644 --- a/packages/core/pipeline/src/plugin/plugins/deploy-to-cdn/index.ts +++ b/packages/core/pipeline/src/plugin/plugins/deploy-to-cdn/index.ts @@ -5,6 +5,7 @@ import Core from "@alicloud/pop-core"; import RPCClient from "@alicloud/pop-core"; import { AliyunAccess } from "../../../access"; import { CertInfo } from "../cert-plugin"; +import { RunStrategy } from "../../../d.ts"; @IsTask(() => { return { @@ -14,16 +15,12 @@ import { CertInfo } from "../cert-plugin"; input: { domainName: { title: "CDN加速域名", - component: { - placeholder: "你在阿里云上配置的CDN加速域名,比如certd.docmirror.cn", - }, + helper: "你在阿里云上配置的CDN加速域名,比如certd.docmirror.cn", required: true, }, certName: { title: "证书名称", - component: { - placeholder: "上传后将以此名称作为前缀备注", - }, + helper: "上传后将以此名称作为前缀备注", }, cert: { title: "域名证书", @@ -44,6 +41,11 @@ import { CertInfo } from "../cert-plugin"; }, }, output: {}, + default: { + strategy: { + runStrategy: RunStrategy.SkipWhenSucceed, + }, + }, }; }) export class DeployCertToAliyunCDN extends AbstractPlugin implements TaskPlugin { diff --git a/packages/core/pipeline/src/utils/util.log.ts b/packages/core/pipeline/src/utils/util.log.ts index c5698cab..4a1bff9c 100644 --- a/packages/core/pipeline/src/utils/util.log.ts +++ b/packages/core/pipeline/src/utils/util.log.ts @@ -2,7 +2,7 @@ import log4js, { LoggingEvent } from "log4js"; const OutputAppender = { configure: (config: any, layouts: any, findAppender: any, levels: any) => { - let layout = layouts.colouredLayout; + let layout = layouts.basicLayout; if (config.layout) { layout = layouts.layout(config.layout.type, config.layout); } diff --git a/packages/core/pipeline/test/pipeline/pipeline.test.ts b/packages/core/pipeline/test/pipeline/pipeline.test.ts index 7a0baee9..494746e0 100644 --- a/packages/core/pipeline/test/pipeline/pipeline.test.ts +++ b/packages/core/pipeline/test/pipeline/pipeline.test.ts @@ -12,7 +12,7 @@ describe("pipeline", function () { } const executor = new Executor({ userId: "test", pipeline, onChanged, accessService: new AccessServiceTest(), storage: new FileStorage() }); - await executor.run(); + await executor.run(1, "user"); // expect(define.name).eq("EchoPlugin"); }); });