Use Hudson object to get global config for plugin
Instead of using the Run object for builds (which may be null) to get the global config for the plugin retrieve it directly from a Hudson instance.
This commit is contained in:
parent
8d334cd9a9
commit
7d54898d4e
|
@ -40,12 +40,15 @@ public enum Phase {
|
|||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public String handlePhase(Run run, String status, TaskListener listener) {
|
||||
HudsonNotificationProperty property = (HudsonNotificationProperty) run.getParent().getProperty(HudsonNotificationProperty.class);
|
||||
if (property != null) {
|
||||
HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty = property.getDescriptor();
|
||||
if (globalProperty.isGloballyEnabled() || property.isEnabled()) {
|
||||
return buildMessage(run.getParent(), run, status);
|
||||
}
|
||||
Hudson hudson = Hudson.getInstance();
|
||||
HudsonNotificationProperty property = (HudsonNotificationProperty)
|
||||
run.getParent().getProperty(HudsonNotificationProperty.class);
|
||||
HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty =
|
||||
(HudsonNotificationProperty.HudsonNotificationPropertyDescriptor)
|
||||
hudson.getDescriptor(HudsonNotificationProperty.class);
|
||||
if ((property != null && property.isEnabled()) ||
|
||||
(globalProperty != null && globalProperty.isGloballyEnabled())) {
|
||||
return buildMessage(run.getParent(), run, status);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.jenkinsci.plugins.ZMQEventPublisher;
|
|||
|
||||
import hudson.Extension;
|
||||
import hudson.EnvVars;
|
||||
import hudson.model.Hudson;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Run;
|
||||
import hudson.model.TaskListener;
|
||||
|
@ -48,9 +49,11 @@ public class RunListenerImpl extends RunListener<Run> {
|
|||
}
|
||||
|
||||
private int getPort(Run build) {
|
||||
HudsonNotificationProperty property = (HudsonNotificationProperty) build.getParent().getProperty(HudsonNotificationProperty.class);
|
||||
if (property != null) {
|
||||
HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty = property.getDescriptor();
|
||||
Hudson hudson = Hudson.getInstance();
|
||||
HudsonNotificationProperty.HudsonNotificationPropertyDescriptor globalProperty =
|
||||
(HudsonNotificationProperty.HudsonNotificationPropertyDescriptor)
|
||||
hudson.getDescriptor(HudsonNotificationProperty.class);
|
||||
if (globalProperty != null) {
|
||||
return globalProperty.getPort();
|
||||
}
|
||||
return 8888;
|
||||
|
|
Loading…
Reference in New Issue