mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
fix: 修复首次创建任务运行时不自动设置当前运行情况的bug
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export * from './plugin-k8s.js';
|
||||
export * from './plugin-script.js';
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import { AbstractTaskPlugin, IsTaskPlugin, pluginGroups, RunStrategy, TaskInput, TaskInstanceContext } from '@certd/pipeline';
|
||||
import { CertInfo, CertReader } from '@certd/plugin-cert';
|
||||
|
||||
export type CustomScriptContext = {
|
||||
CertReader: typeof CertReader;
|
||||
self: CustomScriptPlugin;
|
||||
} & TaskInstanceContext;
|
||||
|
||||
@IsTaskPlugin({
|
||||
name: 'CustomScript',
|
||||
title: '自定义js脚本',
|
||||
desc: '测试',
|
||||
group: pluginGroups.other.key,
|
||||
default: {
|
||||
strategy: {
|
||||
runStrategy: RunStrategy.SkipWhenSucceed,
|
||||
},
|
||||
},
|
||||
})
|
||||
export class CustomScriptPlugin extends AbstractTaskPlugin {
|
||||
@TaskInput({
|
||||
title: '脚本',
|
||||
helper: '自定义js脚本',
|
||||
component: {
|
||||
name: 'a-textarea',
|
||||
vModel: 'value',
|
||||
rows: 10,
|
||||
style: 'background-color: #000c17;color: #fafafa;',
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
script!: string;
|
||||
|
||||
@TaskInput({
|
||||
title: '域名证书',
|
||||
helper: '请选择前置任务输出的域名证书',
|
||||
component: {
|
||||
name: 'pi-output-selector',
|
||||
from: 'CertApply',
|
||||
},
|
||||
required: true,
|
||||
})
|
||||
cert!: CertInfo;
|
||||
|
||||
async onInstance() {}
|
||||
async execute(): Promise<void> {
|
||||
this.logger.info('执行自定义脚本:\n', this.script);
|
||||
const ctx: CustomScriptContext = {
|
||||
CertReader,
|
||||
self: this,
|
||||
...this.ctx,
|
||||
};
|
||||
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor;
|
||||
const func = new AsyncFunction('ctx', this.script);
|
||||
return await func(ctx);
|
||||
}
|
||||
}
|
||||
new CustomScriptPlugin();
|
||||
Reference in New Issue
Block a user