Skip to content

Commit

Permalink
Merge pull request #287 from jglick/getOwnerExecutable
Browse files Browse the repository at this point in the history
Implement `SubTask.getOwnerExecutable`
  • Loading branch information
jglick authored Mar 27, 2023
2 parents 1a36be9 + 0a6bca5 commit 1a63e46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ public String getCookie() {
return j.getNode(label);
}

@Deprecated
@Override public boolean isBuildBlocked() {
return false;
}
Expand Down Expand Up @@ -535,6 +536,10 @@ public String getShortDescription() {
return hasPermission(Item.CANCEL);
}

/**
* @deprecated use {@link #getOwnerExecutable} (which does not require a dependency on this plugin) if your core dep is 2.389+
*/
@Deprecated
public @CheckForNull Run<?,?> run() {
try {
if (!context.isReady()) {
Expand All @@ -548,6 +553,10 @@ public String getShortDescription() {
}
}

/**
* @deprecated use {@link #getOwnerExecutable} (which does not require a dependency on this plugin) if your core dep is 2.389+
*/
@Deprecated
public @CheckForNull Run<?,?> runForDisplay() {
Run<?,?> r = run();
if (r == null && /* not stored prior to 1.13 */runId != null) {
Expand All @@ -560,6 +569,12 @@ public String getShortDescription() {
return r;
}

// TODO 2.389+ @Override
public @CheckForNull Queue.Executable getOwnerExecutable() {
Run<?, ?> r = runForDisplay();
return r instanceof Queue.Executable ? (Queue.Executable) r : null;
}

@Exported
@Override public String getUrl() {
// TODO ideally this would be found via FlowExecution.owner.executable, but how do we check for something with a URL? There is no marker interface for it: JENKINS-26091
Expand Down Expand Up @@ -721,7 +736,7 @@ private String computeEnclosingLabel(FlowNode executorStepNode, List<FlowNode> h
}

@Override public long getEstimatedDuration() {
Run<?,?> r = run();
Run<?,?> r = runForDisplay();
// Not accurate if there are multiple agents in one build, but better than nothing:
return r != null ? r.getEstimatedDuration() : -1;
}
Expand Down Expand Up @@ -995,12 +1010,7 @@ private final class PlaceholderExecutable implements ContinuableExecutable, Acce
}

@Override public Queue.Executable getParentExecutable() {
Run<?, ?> b = runForDisplay();
if (b instanceof Queue.Executable) {
return (Queue.Executable) b;
} else {
return null;
}
return getOwnerExecutable();
}

@Exported
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ private static void assertLogMatches(WorkflowRun build, String regexp) throws IO
Queue.Item[] items = Queue.getInstance().getItems();
assertEquals(1, items.length);
assertEquals(p, items[0].task.getOwnerTask());
// // TODO 2.389+ remove cast
assertEquals(b, ((ExecutorStepExecution.PlaceholderTask) items[0].task).getOwnerExecutable());
assertEquals(items[0], QueueItemAction.getQueueItem(executorStartNode));

assertTrue(Queue.getInstance().cancel(items[0]));
Expand Down

0 comments on commit 1a63e46

Please sign in to comment.