提交 39fbd979 编写于 作者: D Daniel Beck

Merge pull request #1250 from daniel-beck/JENKINS-18048

[FIX JENKINS-18048] Fix link of SCMTriggerCause from UpstreamCause
......@@ -177,6 +177,26 @@ public abstract class Cause {
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.NamingThreadFactory;
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.Jenkins;
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 @@ public class SCMTrigger extends Trigger<Item> {
*/
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 class SCMTrigger extends Trigger<Item> {
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 class SCMTrigger extends Trigger<Item> {
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>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册