Skip to content
Permalink
Browse files

[JENKINS-42584] Fix upstream job priority retrieval

- NPE fix
  • Loading branch information
Ronny Schuetz
Ronny Schuetz committed Mar 23, 2017
1 parent dc12789 commit be0592c259ab6f217c2fd0061cbea217949953b7
Showing with 24 additions and 17 deletions.
  1. +24 −17 src/main/java/jenkins/advancedqueue/PriorityConfigurationPlaceholderTaskHelper.java
@@ -1,6 +1,5 @@
package jenkins.advancedqueue;


import hudson.Plugin;
import hudson.model.Job;
import hudson.model.Queue;
@@ -11,21 +10,29 @@

class PriorityConfigurationPlaceholderTaskHelper {

boolean isPlaceholderTask(Queue.Task task) {
return isPlaceholderTaskUsed() && task instanceof ExecutorStepExecution.PlaceholderTask;
}

PriorityConfigurationCallback getPriority(ExecutorStepExecution.PlaceholderTask task, PriorityConfigurationCallback priorityCallback) {
Job<?, ?> job = (Job<?, ?>) task.getOwnerTask();
ItemInfo itemInfo = QueueItemCache.get().getItem(job.getName());
itemInfo.getPriority();
priorityCallback.setPrioritySelection(itemInfo.getPriority());
return priorityCallback;
}

static boolean isPlaceholderTaskUsed() {
Plugin plugin = Jenkins.getInstance().getPlugin("workflow-durable-task-step");
return plugin != null && plugin.getWrapper().isActive();
}
boolean isPlaceholderTask(Queue.Task task) {
return isPlaceholderTaskUsed() && task instanceof ExecutorStepExecution.PlaceholderTask;
}

PriorityConfigurationCallback getPriority(ExecutorStepExecution.PlaceholderTask task,
PriorityConfigurationCallback priorityCallback) {
Job<?, ?> job = (Job<?, ?>) task.getOwnerTask();
ItemInfo itemInfo = QueueItemCache.get().getItem(job.getName());

// Can be null if job didn't run yet

if (itemInfo != null) {
priorityCallback.setPrioritySelection(itemInfo.getPriority());
} else {
priorityCallback.setPrioritySelection(PrioritySorterConfiguration.get().getStrategy().getDefaultPriority());
}

return priorityCallback;
}

static boolean isPlaceholderTaskUsed() {
Plugin plugin = Jenkins.getInstance().getPlugin("workflow-durable-task-step");
return plugin != null && plugin.getWrapper().isActive();
}

}

0 comments on commit be0592c

Please sign in to comment.
You can’t perform that action at this time.