Skip to content
Permalink
Browse files
Merge pull request #1250 from daniel-beck/JENKINS-18048
[FIX JENKINS-18048] Fix link of SCMTriggerCause from UpstreamCause
  • Loading branch information
daniel-beck committed Jul 26, 2014
2 parents cf5cb70 + 8ec206f commit 39fbd9792e18c3442ecef99b4d24ae44fac989ce
@@ -177,6 +177,26 @@ private UpstreamCause(String upstreamProject, int upstreamBuild, String upstream
this.upstreamCauses = upstreamCauses;
}

@Override
public void onLoad(@Nonnull Run run) {
Item i = Jenkins.getInstance().getItemByFullName(this.upstreamProject);
if (i == null || !(i instanceof Job)) {
// cannot initialize upstream causes
return;
}

Job j = (Job)i;
Run r = j.getBuildByNumber(this.getUpstreamBuild());
if (r == null) {
// build doesn't exist anymore
return;
}

for (Cause c : this.upstreamCauses) {
c.onLoad(r);
}
}

/**
* @since 1.515
*/
@@ -44,6 +44,13 @@
import hudson.util.SequentialExecutionQueue;
import hudson.util.StreamTaskListener;
import hudson.util.TimeUnit2;
import org.apache.commons.io.FileUtils;
import org.apache.commons.jelly.XMLOutput;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
@@ -66,15 +73,15 @@
import jenkins.model.RunAction2;
import jenkins.triggers.SCMTriggerItem;
import net.sf.json.JSONObject;
import org.apache.commons.io.FileUtils;
import org.apache.commons.jelly.XMLOutput;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

import static java.util.logging.Level.*;
import jenkins.model.RunAction2;

import javax.annotation.Nonnull;

/**
* {@link Trigger} that checks for SCM updates periodically.
*
@@ -584,6 +591,8 @@ private SCMTriggerItem job() {
*/
private String pollingLog;

private transient Run run;

public SCMTriggerCause(File logFile) throws IOException {
// TODO: charset of this log file?
this(FileUtils.readFileToString(logFile));
@@ -601,8 +610,14 @@ public SCMTriggerCause() {
this("");
}

@Override
public void onLoad(Run run) {
this.run = run;
}

@Override
public void onAddedTo(Run build) {
this.run = build;
try {
BuildAction a = new BuildAction(build);
FileUtils.writeStringToFile(a.getPollingLogFile(),pollingLog);
@@ -618,6 +633,11 @@ public String getShortDescription() {
return Messages.SCMTrigger_SCMTriggerCause_ShortDescription();
}

@Restricted(DoNotUse.class)
public Run getRun() {
return this.run;
}

@Override
public boolean equals(Object o) {
return o instanceof SCMTriggerCause;
@@ -23,5 +23,6 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<span><a href="pollingLog">${it.shortDescription}</a></span>
<!-- this link loses breadcrumb context, but need absolute URL for upstream cause support (JENKINS-18048) -->
<span><a href="${rootURL}/${it.run.url}pollingLog">${it.shortDescription}</a></span>
</j:jelly>

0 comments on commit 39fbd97

Please sign in to comment.