Skip to content

Commit

Permalink
Merge pull request #1250 from daniel-beck/JENKINS-18048
Browse files Browse the repository at this point in the history
[FIX JENKINS-18048] Fix link of SCMTriggerCause from UpstreamCause
  • Loading branch information
daniel-beck committed Jul 26, 2014
2 parents cf5cb70 + 8ec206f commit 39fbd97
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
20 changes: 20 additions & 0 deletions core/src/main/java/hudson/model/Cause.java
Expand Up @@ -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
*/
Expand Down
30 changes: 25 additions & 5 deletions core/src/main/java/hudson/triggers/SCMTrigger.java
Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down Expand Up @@ -584,6 +591,8 @@ public static class SCMTriggerCause extends Cause {
*/
private String pollingLog;

private transient Run run;

public SCMTriggerCause(File logFile) throws IOException {
// TODO: charset of this log file?
this(FileUtils.readFileToString(logFile));
Expand All @@ -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);
Expand All @@ -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;
Expand Down
Expand Up @@ -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.