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 1 commit
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
11 changes: 11 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 @@ -63,6 +67,13 @@ public RunMessage(@Nonnull Run run) {
set(EventProps.Jenkins.jenkins_object_url, run.getUrl());
set(EventProps.Job.job_run_queueId, Long.toString(run.getQueueId()));

// CSV list of the accumulated causes of this run
final List<String> causes = new ArrayList<>();
for (Cause cause : (List<Cause>) run.getCauses()) {
Copy link
Member

Choose a reason for hiding this comment

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

Might want to wrap all of this in a check for null on the return of run.getCauses().

Copy link
Author

@jordanglassman jordanglassman Sep 18, 2018

Choose a reason for hiding this comment

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

#getCauses is tagged @Nonnull and looks safe:

public @Nonnull List<Cause> getCauses() {
        CauseAction a = getAction(CauseAction.class);
        if (a==null)    return Collections.emptyList();
        return Collections.unmodifiableList(a.getCauses());
    }

Copy link
Author

Choose a reason for hiding this comment

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

@tfennelly ping?

Copy link
Member

Choose a reason for hiding this comment

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

So this will be added on every event, right? I'd restrict it just the run_started event.

causes.add(cause.getClass().getSimpleName());
}
set(EventProps.Job.job_run_causes, StringUtils.join(causes, ","));

Result result = run.getResult();
if (result != null) {
set(EventProps.Job.job_run_status, result.toString());
Expand Down