Skip to content

Commit

Permalink
[FIXED JENKINS-26374] - Avoid NPE for deleted builds in UpstreamCause…
Browse files Browse the repository at this point in the history
…Restriction for jobs

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
  • Loading branch information
oleg-nenashev committed Jan 9, 2015
1 parent 47b292f commit b5c25e3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Expand Up @@ -29,6 +29,7 @@
import hudson.Extension;
import hudson.model.Cause;
import hudson.model.Descriptor;
import hudson.model.Run;
import org.kohsuke.stapler.DataBoundConstructor;

/**
Expand All @@ -38,19 +39,38 @@
public class UpstreamCauseRestriction extends JobCauseRestriction<Cause.UpstreamCause> {

JobRestriction jobRestriction;
final boolean skipCheckForMissingInfo;

@DataBoundConstructor
public UpstreamCauseRestriction(JobRestriction jobRestriction) {
public UpstreamCauseRestriction(JobRestriction jobRestriction,
boolean skipCheckForMissingInfo) {
this.jobRestriction = jobRestriction;
this.skipCheckForMissingInfo = skipCheckForMissingInfo;
}

public UpstreamCauseRestriction(JobRestriction jobRestriction) {
this(jobRestriction, false);
}

public JobRestriction getJobRestriction() {
return jobRestriction;
}


public boolean isSkipCheckForMissingInfo() {
return skipCheckForMissingInfo;
}

@Override
public void validate(Cause.UpstreamCause cause) throws AbortException {
if (jobRestriction != null && !jobRestriction.canTake(cause.getUpstreamRun())) {
final Run upstreamRun = cause.getUpstreamRun();
if (upstreamRun == null) {
if (!skipCheckForMissingInfo) {
throw new AbortException("Upstream build info is missing");
} else {
return;
}
}
if (jobRestriction != null && !jobRestriction.canTake(upstreamRun)) {
throw new AbortException("Job can't be executed due to upstream restrictions");
}
}
Expand Down
Expand Up @@ -23,5 +23,10 @@
-->
<?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" xmlns:sl="/hudson/plugins/sidebar_link">
<f:dropdownDescriptorSelector title="${%Restriction}" field="jobRestriction" />
<f:entry field="skipCheckForMissingInfo" title="${%Skip missing builds}">
<f:checkbox title="${%skipCheckForMissingInfo}" checked="${it.skipCheckForMissingInfo}"/>
</f:entry>
<f:entry>
<f:dropdownDescriptorSelector title="${%Restriction}" field="jobRestriction" />
</f:entry>
</j:jelly>
@@ -0,0 +1 @@
skipCheckForMissingInfo=Don't fail for jobs with missing upstream build info
@@ -0,0 +1,12 @@
<div>
Allows to disable the check for missing upstream build info.
<p>
Upstream build info may be missing in several cases
(e.g. build has been deleted by log rotation handlers).
In such case the plugin won&#39;t be able to extract the data from the upstream build.
</p>
<p>
The enabled control will prevent false-failures, but the security may be violated.
Use the control <b style="color:red">on your own risk</b>
</p>
</div>

0 comments on commit b5c25e3

Please sign in to comment.