Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ export function useStepsPoller(props: RunPollerProps) {
case Result.unstable:
case Result.failure:
case Result.aborted:
if (selectedStepResult && stepResult < selectedStepResult) {
// Return first unstable/failed/aborted step which has a state worse than the selectedStep.
if (
run?.complete &&
selectedStepResult &&
stepResult < selectedStepResult
) {
// If the run is complete return first unstable/failed/aborted step which has a state worse
// than the selectedStep.
// E.g. if the first step state is failure we want to return that over a later unstable step.
return step;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
import com.microsoft.playwright.Page;
import com.microsoft.playwright.junit.UsePlaywright;
import hudson.model.Result;
import io.jenkins.plugins.pipelinegraphview.playwright.ManageAppearancePage;
import io.jenkins.plugins.casc.misc.ConfiguredWithCode;
import io.jenkins.plugins.casc.misc.JenkinsConfiguredWithCodeRule;
import io.jenkins.plugins.casc.misc.junit.jupiter.WithJenkinsConfiguredWithCode;
import io.jenkins.plugins.pipelinegraphview.playwright.PipelineJobPage;
import io.jenkins.plugins.pipelinegraphview.playwright.PlaywrightConfig;
import io.jenkins.plugins.pipelinegraphview.utils.PipelineState;
import io.jenkins.plugins.pipelinegraphview.utils.TestUtils;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.jupiter.api.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
import org.jvnet.hudson.test.Issue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.function.ThrowingSupplier;

@WithJenkins
@WithJenkinsConfiguredWithCode
@UsePlaywright(PlaywrightConfig.class)
class PipelineGraphViewTest {
private static final Logger log = LoggerFactory.getLogger(PipelineGraphViewTest.class);
Expand All @@ -28,10 +27,10 @@ class PipelineGraphViewTest {
// http://localhost:8080/jenkins

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

new PipelineJobPage(p, run.getParent())
.goTo()
Expand Down Expand Up @@ -62,21 +61,46 @@ void smokeTest(Page p, JenkinsRule j) {
.stageIsVisibleInTree("B2");
}

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

CompletableFuture.allOf(run, jenkinsSetup).join();
new PipelineJobPage(p, run.getParent())
.goTo()
.hasBuilds(1)
.nthBuild(0)
.goToBuild()
.goToPipelineOverview()
.hasStagesInGraph(2, "Caught1", "Runs1")
.stageIsVisibleInTree("Parallel1")
.stageIsVisibleInTree("Runs1")
.stageIsSelected("Runs1");

SemaphoreStep.success("wait/1", run);
j.assertBuildStatus(Result.SUCCESS, j.waitForCompletion(run));
}

return run.join();
@Test
@ConfiguredWithCode("configure-appearance.yml")
void failedStageSelected(Page p, JenkinsConfiguredWithCodeRule j) throws Exception {
String name = "Pipeline Success Error Caught";
WorkflowRun run = TestUtils.createAndRunJob(j, name, "gh797_errorAndContinue.jenkinsfile", Result.SUCCESS);

new PipelineJobPage(p, run.getParent())
.goTo()
.hasBuilds(1)
.nthBuild(0)
.goToBuild()
.goToPipelineOverview()
.hasStagesInGraph(2, "Caught1", "Runs1")
.stageIsVisibleInTree("Parallel1")
.stageIsVisibleInTree("Caught1")
.stageIsVisibleInTree("Runs1")
.stageIsSelected("Caught1");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pipeline {
agent any

stages {
stage('Parallel1') {
parallel {
stage('Caught1') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
error 'Oops'
}
}
}
}
}
stage('Runs1') {
steps {
echo 'success'
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pipeline {
agent any

stages {
stage('Parallel1') {
parallel {
stage('Caught1') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
error 'Oops'
}
}
}
}
}
stage('Runs1') {
steps {
semaphore 'wait'
}
}
}
}
Loading