Skip to content

Commit 3cba824

Browse files
authored
Don't select first unsuccessful step when the pipeline is running (jenkinsci#798)
1 parent 7ac0a74 commit 3cba824

File tree

4 files changed

+99
-26
lines changed

4 files changed

+99
-26
lines changed

src/main/frontend/pipeline-console-view/pipeline-console/main/hooks/use-steps-poller.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ export function useStepsPoller(props: RunPollerProps) {
108108
case Result.unstable:
109109
case Result.failure:
110110
case Result.aborted:
111-
if (selectedStepResult && stepResult < selectedStepResult) {
112-
// Return first unstable/failed/aborted step which has a state worse than the selectedStep.
111+
if (
112+
run?.complete &&
113+
selectedStepResult &&
114+
stepResult < selectedStepResult
115+
) {
116+
// If the run is complete return first unstable/failed/aborted step which has a state worse
117+
// than the selectedStep.
113118
// E.g. if the first step state is failure we want to return that over a later unstable step.
114119
return step;
115120
}

src/test/java/io/jenkins/plugins/pipelinegraphview/PipelineGraphViewTest.java

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,21 @@
33
import com.microsoft.playwright.Page;
44
import com.microsoft.playwright.junit.UsePlaywright;
55
import hudson.model.Result;
6-
import io.jenkins.plugins.pipelinegraphview.playwright.ManageAppearancePage;
6+
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
7+
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
8+
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
79
import io.jenkins.plugins.pipelinegraphview.playwright.PipelineJobPage;
810
import io.jenkins.plugins.pipelinegraphview.playwright.PlaywrightConfig;
911
import io.jenkins.plugins.pipelinegraphview.utils.PipelineState;
1012
import io.jenkins.plugins.pipelinegraphview.utils.TestUtils;
11-
import java.util.concurrent.CompletableFuture;
12-
import java.util.function.Supplier;
1313
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
14+
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
1415
import org.junit.jupiter.api.Test;
15-
import org.jvnet.hudson.test.JenkinsRule;
16-
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
16+
import org.jvnet.hudson.test.Issue;
1717
import org.slf4j.Logger;
1818
import org.slf4j.LoggerFactory;
19-
import org.springframework.util.function.ThrowingSupplier;
2019

21-
@WithJenkins
20+
@WithJenkinsConfiguredWithCode
2221
@UsePlaywright(PlaywrightConfig.class)
2322
class PipelineGraphViewTest {
2423
private static final Logger log = LoggerFactory.getLogger(PipelineGraphViewTest.class);
@@ -28,10 +27,10 @@ class PipelineGraphViewTest {
2827
// http://localhost:8080/jenkins
2928

3029
@Test
31-
void smokeTest(Page p, JenkinsRule j) {
30+
@ConfiguredWithCode("configure-appearance.yml")
31+
void smokeTest(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
3232
String name = "Integration Tests";
33-
WorkflowRun run = setupJenkins(p, j.jenkins.getRootUrl(), (ThrowingSupplier<WorkflowRun>)
34-
() -> TestUtils.createAndRunJob(j, name, "smokeTest.jenkinsfile", Result.FAILURE));
33+
WorkflowRun run = TestUtils.createAndRunJob(j, name, "smokeTest.jenkinsfile", Result.FAILURE);
3534

3635
new PipelineJobPage(p, run.getParent())
3736
.goTo()
@@ -62,21 +61,46 @@ void smokeTest(Page p, JenkinsRule j) {
6261
.stageIsVisibleInTree("B2");
6362
}
6463

65-
private static WorkflowRun setupJenkins(Page p, String rootUrl, Supplier<WorkflowRun> setupRun) {
66-
CompletableFuture<WorkflowRun> run = CompletableFuture.supplyAsync(setupRun);
67-
CompletableFuture<Void> jenkinsSetup = CompletableFuture.runAsync(() -> {
68-
log.info("Setting up Jenkins to have the Pipeline Graph View on all pages");
69-
new ManageAppearancePage(p, rootUrl)
70-
.goTo()
71-
.displayPipelineOnJobPage()
72-
.displayPipelineOnBuildPage()
73-
.setPipelineGraphAsConsoleProvider()
74-
.save();
75-
log.info("Jenkins setup complete");
76-
});
64+
@Issue("GH#797")
65+
@Test
66+
@ConfiguredWithCode("configure-appearance.yml")
67+
void runningStageSelected(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
68+
String name = "gh797";
69+
WorkflowRun run = TestUtils.createAndRunJobNoWait(j, name, "gh797_errorAndContinueWithWait.jenkinsfile")
70+
.waitForStart();
71+
SemaphoreStep.waitForStart("wait/1", run);
7772

78-
CompletableFuture.allOf(run, jenkinsSetup).join();
73+
new PipelineJobPage(p, run.getParent())
74+
.goTo()
75+
.hasBuilds(1)
76+
.nthBuild(0)
77+
.goToBuild()
78+
.goToPipelineOverview()
79+
.hasStagesInGraph(2, "Caught1", "Runs1")
80+
.stageIsVisibleInTree("Parallel1")
81+
.stageIsVisibleInTree("Runs1")
82+
.stageIsSelected("Runs1");
83+
84+
SemaphoreStep.success("wait/1", run);
85+
j.assertBuildStatus(Result.SUCCESS, j.waitForCompletion(run));
86+
}
7987

80-
return run.join();
88+
@Test
89+
@ConfiguredWithCode("configure-appearance.yml")
90+
void failedStageSelected(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
91+
String name = "Pipeline Success Error Caught";
92+
WorkflowRun run = TestUtils.createAndRunJob(j, name, "gh797_errorAndContinue.jenkinsfile", Result.SUCCESS);
93+
94+
new PipelineJobPage(p, run.getParent())
95+
.goTo()
96+
.hasBuilds(1)
97+
.nthBuild(0)
98+
.goToBuild()
99+
.goToPipelineOverview()
100+
.hasStagesInGraph(2, "Caught1", "Runs1")
101+
.stageIsVisibleInTree("Parallel1")
102+
.stageIsVisibleInTree("Caught1")
103+
.stageIsVisibleInTree("Runs1")
104+
.stageIsSelected("Caught1");
81105
}
82106
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pipeline {
2+
agent any
3+
4+
stages {
5+
stage('Parallel1') {
6+
parallel {
7+
stage('Caught1') {
8+
steps {
9+
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
10+
error 'Oops'
11+
}
12+
}
13+
}
14+
}
15+
}
16+
stage('Runs1') {
17+
steps {
18+
echo 'success'
19+
}
20+
}
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
pipeline {
2+
agent any
3+
4+
stages {
5+
stage('Parallel1') {
6+
parallel {
7+
stage('Caught1') {
8+
steps {
9+
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
10+
error 'Oops'
11+
}
12+
}
13+
}
14+
}
15+
}
16+
stage('Runs1') {
17+
steps {
18+
semaphore 'wait'
19+
}
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)