Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jenkins pipeline support in ircbot-plugin - an ircNotify() step #21

Merged
merged 19 commits into from
Aug 6, 2019
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
82b410f
pom.xml : update git tag to HEAD like in instant-messaging-plugin
jimklimov Jul 15, 2019
3206794
pom.xml : require at least JDK v8
jimklimov Jul 15, 2019
369a79c
pom.xml : add workflow-step-api
jimklimov Jul 15, 2019
8713e7a
Add IrcNotifyStep.java for basic pipeline step support
jimklimov Jul 15, 2019
afe83ea
IrcNotifyStep.java : Add a constructor with no args (to notify defaul…
jimklimov Jul 18, 2019
6b10c77
Add support for pipeline step `ircNotify customMessage:"something"` a…
jimklimov Jul 18, 2019
12be117
IrcNotifyStep.java : make targets an optional argument, so parameter-…
jimklimov Jul 19, 2019
8acddc5
Copy IrcPublisher jelly configs for IrcNotifyStep too
jimklimov Jul 22, 2019
4eca3a3
README.md : ircNofity in pipeline
jimklimov Jul 22, 2019
ad43503
pom.xml : CI builds: build against instant-messaging.plugin 1.36-SNAP…
jimklimov Jul 18, 2019
a02360a
IrcNotifyStep.java : use a fixed serialVersionUID
jimklimov Aug 6, 2019
4852295
Merge remote-tracking branch 'upstream/master' into pipeline-support
jimklimov Aug 6, 2019
d345757
pom.xml : update instant-messaging-plugin reference to recent officia…
jimklimov Aug 6, 2019
54f8dbf
IrcNotifyStep.java : fix checkstyle warnings (import order)
jimklimov Aug 6, 2019
7b1fecf
IrcNotifyStep.java : fix package this is part of (copy-paste error fr…
jimklimov Aug 6, 2019
ab18341
IrcNotifyStep.java : use a fixed serialVersionUID in IrcNotifyStepExe…
jimklimov Aug 6, 2019
fda499b
IRCColorizer.java : fix javadoc-test complaints
jimklimov Aug 6, 2019
a4d0b58
IrcPublisher.java : fix javadoc-test complaints
jimklimov Aug 6, 2019
5722a26
PircListener.java : fix javadoc-test complaints
jimklimov Aug 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/main/java/hudson/plugins/ircbot/IrcNotifyStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
import hudson.Launcher;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.im.IMMessageTarget;
import hudson.plugins.im.IMConnection;
import hudson.plugins.im.MatrixJobMultiplier;
import hudson.plugins.im.NotificationStrategy;
import hudson.plugins.im.build_notify.BuildToChatNotifier;
import hudson.plugins.im.build_notify.DefaultBuildToChatNotifier;
import hudson.plugins.ircbot.v2.IRCConnectionProvider;
import hudson.plugins.ircbot.v2.IRCMessageTargetConverter;
import hudson.plugins.ircbot.IrcPublisher;
import hudson.util.ListBoxModel;
Expand Down Expand Up @@ -56,6 +59,10 @@ public class IrcNotifyStep extends Step {
private BuildToChatNotifier buildToChatNotifier = new DefaultBuildToChatNotifier();
private MatrixJobMultiplier matrixNotifier = MatrixJobMultiplier.ONLY_PARENT;

// Instead of build status messages, send an arbitrary message to specified
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: As subsequent co-evolution of ircbot and instant-messaging plugins, maybe makes sense to evict this feature there, similarly to extraMessage done in @akomakom's branch.

// or default (global config) targets with the pipeline step (and ignoring
// the strategy and filtering rules options above)
private String customMessage;

@Override
public StepExecution start(StepContext context) throws Exception {
Expand Down Expand Up @@ -138,6 +145,15 @@ public void setNotificationStrategy(String notificationStrategy) {
this.notificationStrategy = notificationStrategy;
}

public String getCustomMessage() {
return customMessage;
}

@DataBoundSetter
public void setCustomMessage(String customMessage) {
this.customMessage = customMessage;
}

private static class IrcNotifyStepExecution extends SynchronousNonBlockingStepExecution<Void> {
private transient final IrcNotifyStep step;

Expand Down Expand Up @@ -166,11 +182,19 @@ protected Void run() throws Exception {
step.buildToChatNotifier,
step.matrixNotifier
);
publisher.perform(
if (step.customMessage == null || step.customMessage.isEmpty()) {
publisher.perform(
getContext().get(Run.class),
getContext().get(FilePath.class),
getContext().get(Launcher.class),
getContext().get(TaskListener.class));
} else {
IMConnection imConnection = //publisher.getIMConnection();
IRCConnectionProvider.getInstance().currentConnection();
for (IMMessageTarget target : CONVERTER.allFromString(targets)) {
imConnection.send(target, step.customMessage);
}
}

return null;
}
Expand Down