Skip to content

Commit

Permalink
[FIXED JENKINS-43055] Use a FlowExecutionListener to attach the graph…
Browse files Browse the repository at this point in the history
… listener
  • Loading branch information
abayer committed May 16, 2017
1 parent cde871f commit 2671aeb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
Expand Up @@ -220,9 +220,6 @@ public class Utils {
ModelASTStages stages = model.stages

stages.removeSourceLocation()
if (r.getAction(SyntheticStageGraphListener.GraphListenerAction.class) == null) {
r.addAction(new SyntheticStageGraphListener.GraphListenerAction())
}
if (r.getAction(ExecutionModelAction.class) == null) {
r.addAction(new ExecutionModelAction(stages))
}
Expand Down
Expand Up @@ -24,17 +24,15 @@

package org.jenkinsci.plugins.pipeline.modeldefinition;

import hudson.model.InvisibleAction;
import hudson.model.Run;
import jenkins.model.RunAction2;
import hudson.Extension;
import org.jenkinsci.plugins.pipeline.SyntheticStage;
import org.jenkinsci.plugins.workflow.actions.LabelAction;
import org.jenkinsci.plugins.workflow.actions.TagsAction;
import org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionListener;
import org.jenkinsci.plugins.workflow.flow.GraphListener;
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.jenkinsci.plugins.workflow.support.steps.StageStep;

import java.io.IOException;
Expand Down Expand Up @@ -79,29 +77,12 @@ private void attachTag(FlowNode currentNode, String syntheticContext) {
}
}

public static class GraphListenerAction extends InvisibleAction implements RunAction2 {
@Extension
public static class FlowExecutionListenerImpl extends FlowExecutionListener {
@Override
public void onLoad(Run<?, ?> r) {
if (r != null && r instanceof WorkflowRun) {
WorkflowRun run = (WorkflowRun) r;
attachListener(run);
}
}

@Override
public void onAttached(Run<?, ?> r) {
if (r != null && r instanceof WorkflowRun) {
WorkflowRun run = (WorkflowRun) r;
attachListener(run);
}
}

private void attachListener(WorkflowRun run) {
if (run != null) {
FlowExecution exec = run.getExecution();
if (exec != null && !exec.isComplete()) {
exec.addListener(new SyntheticStageGraphListener());
}
public void onRunning(FlowExecution execution) {
if (execution != null && !execution.isComplete()) {
execution.addListener(new SyntheticStageGraphListener());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.29</version>
<version>2.31-20170516.164140-1</version> <!-- TODO: update when https://github.com/jenkinsci/workflow-cps-plugin/pull/127 is merged and released -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand All @@ -85,7 +85,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.11</version>
<version>2.14-20170516.161836-2</version> <!-- TODO: update when https://github.com/jenkinsci/workflow-api-plugin/pull/36 is merged and released -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down

0 comments on commit 2671aeb

Please sign in to comment.