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 CSV-separated job run causes to RunMessage #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/main/java/org/jenkinsci/plugins/pubsub/EventProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ enum Job {
* Job run SCM commit Id, if relevant.
*/
job_run_commitId,
/**
* Causes of this run.
*/
job_run_causes
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/jenkinsci/plugins/pubsub/RunMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@
*/
package org.jenkinsci.plugins.pubsub;

import hudson.model.Cause;
import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;
import hudson.security.AccessControlled;
import org.apache.commons.lang.StringUtils;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* Jenkins {@link Run} domain model {@link PubsubBus} message instance.
Expand Down Expand Up @@ -118,4 +122,14 @@ protected AccessControlled getAccessControlled() {
}
return run;
}

public RunMessage withCauses(@Nonnull Run run) {
// csv list of the accumulated causes of this run
final List<String> causes = new ArrayList<>();
for (Cause cause : (List<Cause>) run.getCauses()) {
causes.add(cause.getClass().getSimpleName());
}
set(EventProps.Job.job_run_causes, StringUtils.join(causes, ","));
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ public class SyncRunListener extends RunListener<Run<?,?>> {
@Override
public void onStarted(Run<?, ?> run, TaskListener listener) {
try {
PubsubBus.getBus().publish(new RunMessage(run)
.setEventName(Events.JobChannel.job_run_started)
PubsubBus.getBus().publish(
new RunMessage(run)
.withCauses(run)
.setEventName(Events.JobChannel.job_run_started)
);
} catch (MessageException e) {
LOGGER.log(Level.WARNING, "Error publishing Run start event.", e);
Expand Down