From 2ad3ed5c11a536b9e8d3421973c52178f15e4b79 Mon Sep 17 00:00:00 2001 From: Sudhir Verma Date: Wed, 7 Jul 2021 15:49:31 +0530 Subject: [PATCH] Fix streaming logs output from a PipelineRun on start --- README.md | 3 ++- package.json | 6 ++++++ src/tekton/addtrigger.ts | 10 ++++++++++ src/tekton/pipelinerun.ts | 8 ++++++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 85990004..907b4d27 100644 --- a/README.md +++ b/README.md @@ -149,9 +149,10 @@ Development of the Tekton Pipelines Extension is largely following development o ### Extension Configuration Settings - * `Tekton Pipelines: Show Channel On Output` - Show Tekton Pipelines output channel when new text added to output stream + * `Tekton Pipelines: Show Channel On Output` - Show Tekton Pipelines output channel when new text added to output stream. * `Tekton Pipelines: Output verbosity level` - Output verbosity level (value between 0 and 9) for Tekton Pipeline Start, Push and Watch commands in output channel and integrated terminal. * `Tekton Pipelines: Show reference resource notification` - Enable/disable to check Task and ClusterTask Reference Resource. + * `Tekton Pipelines: Show PipelineRun Follow Logs` - Show pipelineRun follow logs while starting pipeline. ### Dependencies diff --git a/package.json b/package.json index ab25d38a..8e040f71 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,12 @@ "default": false, "description": "Show Tekton Pipeline output channel when new text added to output stream" }, + "vs-tekton.showPipelineRunFollowLogs": { + "title": "Show pipelineRun follow Logs", + "type": "boolean", + "default": true, + "description": "Show pipelineRun follow logs while starting pipeline." + }, "vs-tekton.outputVerbosityLevel": { "title": "Output Verbosity Level", "type": "number", diff --git a/src/tekton/addtrigger.ts b/src/tekton/addtrigger.ts index 74883b52..25b66123 100644 --- a/src/tekton/addtrigger.ts +++ b/src/tekton/addtrigger.ts @@ -27,6 +27,8 @@ import { getStderrString } from '../util/stderrstring'; import { Command } from '../cli-command'; import semver = require('semver'); import { ClusterTaskModel, EventListenerModel, PipelineRunModel, TaskModel, TriggerTemplateModel } from '../util/resource-kind'; +import { showPipelineRunPreview } from '../pipeline/pipeline-preview'; +import { PipelineRun } from './pipelinerun'; export enum WorkspaceResource { Secret = 'secret', @@ -96,6 +98,14 @@ export async function k8sCreate(trigger: TriggerTemplateKind | EventListenerKind if (kind === PipelineRunModel.kind && !result.error) { const message = 'Pipeline successfully started'; telemetryLog(commandId, message); + if (TektonItem.ShowPipelineRun()) { + const pipelineRunNameRegex = new RegExp(`${trigger.metadata.generateName}\\w*`); + const pipelineRunName = result.stdout.match(pipelineRunNameRegex)[0]; + if (pipelineRunName) { + await showPipelineRunPreview(pipelineRunName); + if (vscode.workspace.getConfiguration('vs-tekton').get('showPipelineRunFollowLogs')) PipelineRun.pipelineRunFollowLogs(pipelineRunName); + } + } vscode.window.showInformationMessage(message); } if ((kind === TaskModel.kind || kind === ClusterTaskModel.kind) && !result.error) { diff --git a/src/tekton/pipelinerun.ts b/src/tekton/pipelinerun.ts index 8680914e..80f12853 100644 --- a/src/tekton/pipelinerun.ts +++ b/src/tekton/pipelinerun.ts @@ -56,10 +56,14 @@ export class PipelineRun extends TektonItem { if (!pipelineRun){ return; } + this.pipelineRunFollowLogs(pipelineRun.getName()); + } + + static async pipelineRunFollowLogs(pipelineRunName: string): Promise { if (workspace.getConfiguration('vs-tekton').get('showLogInEditor')) { - showLogInEditor(Command.showPipelineRunFollowLogs(pipelineRun.getName()), `Log: ${pipelineRun.getName()}`); + showLogInEditor(Command.showPipelineRunFollowLogs(pipelineRunName), `Log: ${pipelineRunName}`); } else { - PipelineRun.tkn.executeInTerminal(Command.showPipelineRunFollowLogs(pipelineRun.getName())); + PipelineRun.tkn.executeInTerminal(Command.showPipelineRunFollowLogs(pipelineRunName)); } }