Skip to content
Permalink
Browse files
[FIX JENKINS-18048] Fix link of SCMTriggerCause from UpstreamCause
- UpstreamCause now tries to initialize upstream causes with the
  correct build in onLoad
- SCMTriggerCause stores build reference and uses its URL to build
  absolute link to changelog
  • Loading branch information
daniel-beck committed May 23, 2014
1 parent 016f304 commit e937b099cb49e7458159980adc4b59d1f98b057c
@@ -157,6 +157,26 @@ private UpstreamCause(String upstreamProject, int upstreamBuild, String upstream
this.upstreamCauses = upstreamCauses;
}

@Override
public void onLoad(@Nonnull AbstractBuild<?, ?> build) {
Item i = Jenkins.getInstance().getItemByFullName(this.upstreamProject);
if (i == null || !(i instanceof AbstractProject)) {
// cannot initialize upstream causes
return;
}

AbstractProject j = (AbstractProject)i;
AbstractBuild 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
*/
@@ -46,6 +46,8 @@
import hudson.util.SequentialExecutionQueue;
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;

@@ -72,6 +74,8 @@
import static java.util.logging.Level.*;
import jenkins.model.RunAction2;

import javax.annotation.Nonnull;

/**
* {@link Trigger} that checks for SCM updates periodically.
*
@@ -536,6 +540,8 @@ public int hashCode() {
*/
private String pollingLog;

private transient AbstractBuild<?, ?> build;

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

@Override
public void onLoad(@Nonnull AbstractBuild<?, ?> build) {
this.build = build;
}

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

@Restricted(DoNotUse.class)
public AbstractBuild<?, ?> getBuild() {
return this.build;
}

@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.build.url}pollingLog">${it.shortDescription}</a></span>
</j:jelly>

0 comments on commit e937b09

Please sign in to comment.