Merge pull request #1637 from pikasTech/fix/unidesk-host-pac-paths
Pipelines as Code CI / hwlab-web-probe-sentinel-nc01- Success
Pipelines as Code CI / unidesk-host- Failed

修复 UniDesk Host PaC 路径与失败诊断
This commit is contained in:
Lyon
2026-07-10 10:05:04 +08:00
committed by GitHub
3 changed files with 59 additions and 10 deletions
@@ -398,7 +398,7 @@ function kubectlJson(args, fallback, context) {
function condition(item) {
const c = (item.status?.conditions || []).find((x) => x.type === 'Succeeded') || {};
return { status: c.status || '', reason: c.reason || '' };
return { status: c.status || '', reason: c.reason || '', message: c.message || '' };
}
function durationSeconds(start, done) {
@@ -523,7 +523,20 @@ function envReuseForPipelineRun(namespace, name) {
return state;
}
function taskSummary(taskRuns, name) {
function failedStep(item) {
const steps = (item.status?.steps || []).map((step) => ({
name: step.name || null,
container: step.container || null,
exitCode: Number.isInteger(step.terminated?.exitCode) ? step.terminated.exitCode : null,
reason: step.terminated?.reason || null,
terminationReason: step.terminationReason || null,
}));
return steps.find((step) => step.exitCode !== null && step.exitCode !== 0 && step.terminationReason !== 'Skipped')
|| steps.find((step) => step.terminationReason === 'Error')
|| null;
}
function taskSummary(taskRuns, name, namespace) {
const rows = (taskRuns.items || [])
.filter((item) => item.metadata?.labels?.['tekton.dev/pipelineRun'] === name)
.map((item) => {
@@ -532,19 +545,31 @@ function taskSummary(taskRuns, name) {
name: item.metadata?.name || '',
status: c.status || null,
reason: c.reason || null,
message: c.message || null,
failedStep: failedStep(item),
startTime: item.status?.startTime || null,
completionTime: item.status?.completionTime || null,
durationSeconds: durationSeconds(item.status?.startTime, item.status?.completionTime),
};
});
const longest = [...rows].sort((a, b) => (b.durationSeconds || 0) - (a.durationSeconds || 0))[0] || null;
return { count: rows.length, longest };
const failed = rows.find((row) => row.status === 'False') || null;
const target = process.env.UNIDESK_PAC_TARGET_ID || '';
return {
count: rows.length,
longest,
failed,
details: detailId ? rows : undefined,
logsCommand: target && namespace
? `trans ${target}:k3s logs -n ${namespace} -l tekton.dev/pipelineRun=${name} --all-containers --tail=240`
: null,
};
}
function rowFor(consumer, item, taskRuns) {
const params = mapParams(item.spec?.params);
const c = condition(item);
const tasks = taskSummary(taskRuns, item.metadata.name);
const tasks = taskSummary(taskRuns, item.metadata.name, consumer.namespace);
const labels = item.metadata?.labels || {};
const annotations = item.metadata?.annotations || {};
return {
@@ -618,7 +643,18 @@ if (!pr) {
}
function cond(item) {
const c = (item.status?.conditions || []).find((x) => x.type === 'Succeeded') || {};
return { status: c.status || '', reason: c.reason || '' };
return { status: c.status || '', reason: c.reason || '', message: c.message || '' };
}
function failedStep(item) {
const steps = (item.status?.steps || []).map((step) => ({
name: step.name || null,
exitCode: Number.isInteger(step.terminated?.exitCode) ? step.terminated.exitCode : null,
reason: step.terminated?.reason || null,
terminationReason: step.terminationReason || null,
}));
return steps.find((step) => step.exitCode !== null && step.exitCode !== 0 && step.terminationReason !== 'Skipped')
|| steps.find((step) => step.terminationReason === 'Error')
|| null;
}
function durationSeconds(item) {
const start = item.status?.startTime;
@@ -632,7 +668,7 @@ const rows = (data.items || [])
.slice(0, 20)
.map((item) => {
const c = cond(item);
return { name: item.metadata.name, pipelineRun: item.metadata.labels?.['tekton.dev/pipelineRun'] || null, status: c.status, reason: c.reason, startTime: item.status?.startTime || null, completionTime: item.status?.completionTime || null, durationSeconds: durationSeconds(item) };
return { name: item.metadata.name, pipelineRun: item.metadata.labels?.['tekton.dev/pipelineRun'] || null, status: c.status, reason: c.reason, message: c.message || null, failedStep: failedStep(item), startTime: item.status?.startTime || null, completionTime: item.status?.completionTime || null, durationSeconds: durationSeconds(item) };
});
process.stdout.write(JSON.stringify(rows));
NODE
@@ -1104,7 +1104,10 @@ function renderStatus(result: Record<string, unknown>): RenderedCliResult {
...table(["NAME", "STATUS", "REASON", "DURATION_S", "SOURCE"], [[stringValue(latest.name), stringValue(latest.status), stringValue(latest.reason), stringValue(latest.durationSeconds), short(stringValue(latest.sourceCommit))]]),
"",
"TASKRUN DURATIONS",
...(taskRuns.length === 0 ? ["-"] : table(["TASKRUN", "STATUS", "REASON", "DURATION_S"], taskRuns.map((item) => [short(stringValue(item.name), 56), stringValue(item.status), stringValue(item.reason), stringValue(item.durationSeconds)]))),
...(taskRuns.length === 0 ? ["-"] : table(["TASKRUN", "STATUS", "REASON", "FAILED_STEP", "EXIT", "DURATION_S"], taskRuns.map((item) => {
const failedStep = record(item.failedStep);
return [short(stringValue(item.name), 48), stringValue(item.status), stringValue(item.reason), stringValue(failedStep.name), stringValue(failedStep.exitCode), stringValue(item.durationSeconds)];
}))),
"",
"IMAGE / GITOPS",
...table(["IMAGE_STATUS", "ENV_REUSE", "ENV_ID", "DIGEST", "GITOPS"], [[stringValue(artifact.imageStatus), stringValue(artifact.envReuse), stringValue(artifact.envIdentity), short(stringValue(artifact.digest), 18), short(stringValue(artifact.gitopsCommit))]]),
@@ -1693,6 +1696,8 @@ function renderHistoryDetail(row: Record<string, unknown>): string[] {
const envReuse = record(row.envReuse);
const taskRuns = record(row.taskRuns);
const longest = record(taskRuns.longest);
const failed = record(taskRuns.failed);
const failedStep = record(failed.failedStep);
return [
"",
"DETAIL",
@@ -1706,8 +1711,16 @@ function renderHistoryDetail(row: Record<string, unknown>): string[] {
["taskRuns", stringValue(taskRuns.count)],
["longestTask", stringValue(longest.name)],
["longestTaskDurationS", stringValue(longest.durationSeconds)],
["failedTask", stringValue(failed.name)],
["failedStep", stringValue(failedStep.name)],
["failedStepExit", stringValue(failedStep.exitCode)],
["failedStepTermination", stringValue(failedStep.terminationReason ?? failedStep.reason)],
["failure", compactLine(stringValue(failed.message))],
["envReuseSource", stringValue(envReuse.source)],
]),
"",
"LOGS",
` ${stringValue(taskRuns.logsCommand)}`,
];
}