Skip to content
Permalink
Browse files

[FIXED JENKINS-9560] new bot command to show the currently building jobs

  • Loading branch information...
kutzi
kutzi committed May 2, 2011
1 parent 0f27ccb commit c2544d10dae97240fcd1717812799b4e076412f0
Showing with 72 additions and 0 deletions.
  1. +72 −0 src/main/java/hudson/plugins/im/bot/CurrentlyBuildingCommand.java
@@ -0,0 +1,72 @@
package hudson.plugins.im.bot;

import hudson.Extension;
import hudson.Util;
import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Hudson;
import hudson.model.Queue.Executable;
import hudson.plugins.im.IMChat;
import hudson.plugins.im.IMException;
import hudson.plugins.im.IMMessage;
import hudson.plugins.im.Sender;

import java.util.Arrays;
import java.util.Collection;

/**
* CurrentlyBuilding command for instant messaging plugin.
*
* Generates a list of jobs in progress.
*
* @author Bjoern Kasteleiner
*/
@Extension
public class CurrentlyBuildingCommand extends BotCommand {

private static final String HELP_MESSAGE = " - list jobs which are currently in progress";

@Override
public Collection<String> getCommandNames() {
return Arrays.asList("currentlyBuilding", "cb");
}

@Override
public void executeCommand(Bot bot, IMChat chat, IMMessage message,
Sender sender, String[] args) throws IMException {
StringBuffer msg = new StringBuffer();
msg.append("Currently building:");
boolean currentlyJobsInProgess = false;
for (Computer computer : Hudson.getInstance().getComputers()) {
for (Executor executor : computer.getExecutors()) {
Executable currentExecutable = executor.getCurrentExecutable();
if (currentExecutable != null) {
currentlyJobsInProgess = true;
msg.append("\n- ");
msg.append(computer.getDisplayName());
msg.append("#");
msg.append(executor.getNumber());
msg.append(": ");
msg.append(currentExecutable.getParent().getDisplayName());
msg.append(" (Elapsed time: ");
msg.append(Util.getTimeSpanString(executor.getElapsedTime()));
msg.append(", Estimated remaining time: ");
msg.append(executor.getEstimatedRemainingTime());
msg.append(")");
}
}
}

if (!currentlyJobsInProgess) {
msg.append("\n- No jobs are running.");
}

chat.sendMessage(msg.toString());
}

@Override
public String getHelp() {
return HELP_MESSAGE;
}

}

0 comments on commit c2544d1

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