Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<gitHubRepo>jenkinsci/pipeline-graph-view-plugin</gitHubRepo>
<!-- Baseline Jenkins version you use to build the plugin. Users must have this version or newer to run. -->
<jenkins.baseline>2.504</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<jenkins.version>2.531-rc37563.302edded866d</jenkins.version>
<node.version>24.2.0</node.version>
<npm.version>11.3.0</npm.version>
<spotless.check.skip>false</spotless.check.skip>
Expand Down Expand Up @@ -138,6 +138,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>1395.v515f67ea_db_10</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>1395.v515f67ea_db_10</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
Expand Down
16 changes: 11 additions & 5 deletions src/main/frontend/common/RestClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface StepLogBufferInfo {
endByte: number;
pending?: Promise<void>;
consoleAnnotator?: string;
hasTrailingNewLine?: boolean;
lastFetched?: number;
stopTailing?: boolean;
exceptionText?: string[];
Expand Down Expand Up @@ -88,18 +89,23 @@ export async function getConsoleTextOffset(
startByte: number,
consoleAnnotator: string,
): Promise<ConsoleLogData | null> {
const headers = new Headers();
const headers = new Headers({ Accept: "multipart/form-data" });
if (consoleAnnotator) headers.set("X-ConsoleAnnotator", consoleAnnotator);
try {
const response = await fetch(
`consoleOutput?nodeId=${stepId}&startByte=${startByte}`,
`../execution/node/${stepId}/log/logText/progressiveHtml?start=${startByte.toString()}`,
{ headers },
);
if (!response.ok) throw response.statusText;
const json = await response.json();
const data = await response.formData();
const text = data.get("text") as string;
const meta = JSON.parse(data.get("meta") as string);
return {
...json.data,
consoleAnnotator: response.headers.get("X-ConsoleAnnotator") || "",
text,
startByte: meta.start,
endByte: meta.end,
nodeIsActive: !meta.completed,
consoleAnnotator: meta.consoleAnnotator,
};
} catch (e) {
console.error(`Caught error when fetching console: '${e}'`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ describe("incremental log fetching", function () {
lines: ["0"],
endByte: 2,
consoleAnnotator: "0",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -348,6 +349,7 @@ describe("incremental log fetching", function () {
lines: ["0", "1"],
endByte: 4,
consoleAnnotator: "1",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -366,6 +368,7 @@ describe("incremental log fetching", function () {
lines: ["0", "1", "2", "3"],
endByte: 8,
consoleAnnotator: "3",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -384,6 +387,7 @@ describe("incremental log fetching", function () {
lines: ["0", "1", "2", "3"],
endByte: 8,
consoleAnnotator: "empty",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -402,6 +406,66 @@ describe("incremental log fetching", function () {
lines: ["0", "1", "2", "3", "4"],
endByte: 10,
consoleAnnotator: "4",
hasTrailingNewLine: true,
},
},
],
"when gluing lines together": [
{
clickMoreStartByte: TAIL_CONSOLE_LOG,
fetchStartByte: TAIL_CONSOLE_LOG,
fetchConsoleAnnotator: "",
logData: {
text: "0\n1",
startByte: 0,
endByte: 3,
nodeIsActive: true,
consoleAnnotator: "1",
},
result: {
startByte: 0,
lines: ["0", "1"],
endByte: 3,
consoleAnnotator: "1",
hasTrailingNewLine: false,
},
},
{
clickMoreStartByte: TAIL_CONSOLE_LOG,
fetchStartByte: 3,
fetchConsoleAnnotator: "1",
logData: {
text: "2\n3",
startByte: 3,
endByte: 6,
nodeIsActive: true,
consoleAnnotator: "3",
},
result: {
startByte: 0,
lines: ["0", "12", "3"],
endByte: 6,
consoleAnnotator: "3",
hasTrailingNewLine: false,
},
},
{
clickMoreStartByte: TAIL_CONSOLE_LOG,
fetchStartByte: 6,
fetchConsoleAnnotator: "3",
logData: {
text: "\n4\n",
startByte: 6,
endByte: 9,
nodeIsActive: true,
consoleAnnotator: "4",
},
result: {
startByte: 0,
lines: ["0", "12", "3", "4"],
endByte: 9,
consoleAnnotator: "4",
hasTrailingNewLine: true,
},
},
],
Expand All @@ -422,6 +486,7 @@ describe("incremental log fetching", function () {
lines: ["0"],
endByte: 1_000_002,
consoleAnnotator: "0",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -440,6 +505,7 @@ describe("incremental log fetching", function () {
lines: ["0", "1"],
endByte: 1_000_004,
consoleAnnotator: "1",
hasTrailingNewLine: true,
},
},
],
Expand All @@ -460,6 +526,7 @@ describe("incremental log fetching", function () {
lines: ["0"],
endByte: 1_000_002,
consoleAnnotator: "0",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -478,6 +545,7 @@ describe("incremental log fetching", function () {
lines: ["xxx", "0"],
endByte: 1_000_002,
consoleAnnotator: "x",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -496,6 +564,7 @@ describe("incremental log fetching", function () {
lines: ["yyy", "xxx", "0"],
endByte: 1_000_002,
consoleAnnotator: "y",
hasTrailingNewLine: true,
},
},
],
Expand All @@ -516,6 +585,7 @@ describe("incremental log fetching", function () {
lines: ["0"],
endByte: 1_000_002,
consoleAnnotator: "0",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -534,6 +604,7 @@ describe("incremental log fetching", function () {
lines: ["xxx", "0"],
endByte: 1_000_002,
consoleAnnotator: "x",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -552,6 +623,7 @@ describe("incremental log fetching", function () {
lines: ["xxx", "0", "1"],
endByte: 1_000_004,
consoleAnnotator: "1",
hasTrailingNewLine: true,
},
},
{
Expand All @@ -571,6 +643,7 @@ describe("incremental log fetching", function () {
endByte: 1_000_004,
consoleAnnotator: "y",
stopTailing: true,
hasTrailingNewLine: true,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,23 @@ async function updateStepBuffer(
}

const newLogLines = response.text.split("\n");
if (newLogLines[newLogLines.length - 1] === "") {
const hasTrailingNewLine = response.text.endsWith("\n");
if (!response.text || hasTrailingNewLine) {
// Remove trailing empty new line caused by a) splitting an empty string or b) a trailing new line character in the response.
newLogLines.pop();
}

const exceptionText = stepBuffer.exceptionText || [];
if (stepBuffer.endByte > 0 && stepBuffer.endByte === startByte) {
stepBuffer.lines.length -= exceptionText.length;
if (
!stepBuffer.hasTrailingNewLine &&
stepBuffer.lines.length > 0 &&
newLogLines.length > 0
) {
// Combine a previously broken up line back together.
stepBuffer.lines[stepBuffer.lines.length - 1] += newLogLines.shift();
}
stepBuffer.lines = [...stepBuffer.lines, ...newLogLines, ...exceptionText];
} else {
stepBuffer.lines = newLogLines.concat(exceptionText);
Expand All @@ -77,6 +86,10 @@ async function updateStepBuffer(

stepBuffer.endByte = response.endByte;
stepBuffer.consoleAnnotator = response.consoleAnnotator;
if (response.text) {
// Only overwrite when more text was available.
stepBuffer.hasTrailingNewLine = hasTrailingNewLine;
}
if (!response.nodeIsActive) {
// We've reached the end of the log now.
stepBuffer.stopTailing = true;
Expand Down