From 1f6a8f9e7d9de6f24015d8fec74da0a30b1ad1a6 Mon Sep 17 00:00:00 2001 From: toshihirock Date: Sun, 26 Oct 2014 15:58:20 +0900 Subject: [PATCH] apply global config --- .../java/jenkins/plugins/slack/SlackListener.java | 1 + .../java/jenkins/plugins/slack/SlackNotifier.java | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/jenkins/plugins/slack/SlackListener.java b/src/main/java/jenkins/plugins/slack/SlackListener.java index 5fdc8d4c..585739f6 100755 --- a/src/main/java/jenkins/plugins/slack/SlackListener.java +++ b/src/main/java/jenkins/plugins/slack/SlackListener.java @@ -50,6 +50,7 @@ FineGrainedNotifier getNotifier(AbstractProject project) { Map, Publisher> map = project.getPublishersList().toMap(); for (Publisher publisher : map.values()) { if (publisher instanceof SlackNotifier) { + ((SlackNotifier)publisher).update(); return new ActiveNotifier((SlackNotifier) publisher); } } diff --git a/src/main/java/jenkins/plugins/slack/SlackNotifier.java b/src/main/java/jenkins/plugins/slack/SlackNotifier.java index ce45333f..16ea537a 100755 --- a/src/main/java/jenkins/plugins/slack/SlackNotifier.java +++ b/src/main/java/jenkins/plugins/slack/SlackNotifier.java @@ -77,6 +77,14 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListen return true; } + public void update() { + this.teamDomain = getDescriptor().teamDomain; + this.authToken = getDescriptor().token; + this.buildServerUrl = getDescriptor().buildServerUrl; + this.room = getDescriptor().room; + this.sendAs = getDescriptor().sendAs; + } + @Extension public static class DescriptorImpl extends BuildStepDescriptor { private String teamDomain; @@ -133,11 +141,6 @@ public boolean configure(StaplerRequest sr, JSONObject formData) throws FormExce if (buildServerUrl != null && !buildServerUrl.endsWith("/")) { buildServerUrl = buildServerUrl + "/"; } - try { - new SlackNotifier(teamDomain, token, room, buildServerUrl, sendAs); - } catch (Exception e) { - throw new FormException("Failed to initialize notifier - check your global notifier configuration settings", e, ""); - } save(); return super.configure(sr, formData); } @@ -200,6 +203,7 @@ public boolean prebuild(AbstractBuild build, BuildListener listener) { for (Publisher publisher : map.values()) { if (publisher instanceof SlackNotifier) { logger.info("Invoking Started..."); + ((SlackNotifier)publisher).update(); new ActiveNotifier((SlackNotifier) publisher).started(build); } }