Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-26823] Prevent concurrent builds blocking
If a previous build is still running, it will be ignored (along with
any earlier builds).
  • Loading branch information
seanf committed Feb 19, 2015
1 parent f35fb2e commit 30e5b57
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
17 changes: 17 additions & 0 deletions src/main/java/hudson/plugins/cobertura/BuildUtils.java
@@ -0,0 +1,17 @@
package hudson.plugins.cobertura;

import hudson.model.AbstractBuild;

public class BuildUtils {
public static AbstractBuild<?, ?> getPreviousNotFailedCompletedBuild(AbstractBuild<?, ?> b) {
while (true) {
b = b.getPreviousNotFailedBuild();
if (b == null) {
return null;
}
if (!b.isBuilding()) {
return b;
}
}
}
}
Expand Up @@ -159,7 +159,7 @@ public CoberturaBuildAction getPreviousResult() {
static CoberturaBuildAction getPreviousResult(AbstractBuild<?, ?> start) {
AbstractBuild<?, ?> b = start;
while (true) {
b = b.getPreviousNotFailedBuild();
b = BuildUtils.getPreviousNotFailedCompletedBuild(b);
if (b == null) {
return null;
}
Expand Down
Expand Up @@ -61,7 +61,7 @@ public String getUrlName() {
* @return Value for property 'lastResult'.
*/
public CoberturaBuildAction getLastResult() {
for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(); b != null; b = b.getPreviousNotFailedBuild()) {
for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(); b != null; b = BuildUtils.getPreviousNotFailedCompletedBuild(b)) {
if (b.getResult() == Result.FAILURE || (b.getResult() != Result.SUCCESS && onlyStable))
continue;
CoberturaBuildAction r = b.getAction(CoberturaBuildAction.class);
Expand All @@ -79,7 +79,7 @@ public CoberturaBuildAction getLastResult() {
* @return Value for property 'lastResult'.
*/
public Integer getLastResultBuild() {
for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(); b != null; b = b.getPreviousNotFailedBuild()) {
for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(); b != null; b = BuildUtils.getPreviousNotFailedCompletedBuild(b)) {
if (b.getResult() == Result.FAILURE || (b.getResult() != Result.SUCCESS && onlyStable))
continue;
CoberturaBuildAction r = b.getAction(CoberturaBuildAction.class);
Expand Down
Expand Up @@ -500,7 +500,7 @@ public Action getProjectAction(AbstractProject<?, ?> project) {
* {@inheritDoc}
*/
public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.BUILD;
return BuildStepMonitor.NONE;
}

/**
Expand Down
Expand Up @@ -4,6 +4,7 @@
import hudson.model.Api;
import hudson.model.Item;
import hudson.model.Run;
import hudson.plugins.cobertura.BuildUtils;
import hudson.plugins.cobertura.Chartable;
import hudson.plugins.cobertura.CoberturaBuildAction;
import hudson.plugins.cobertura.CoverageChart;
Expand Down Expand Up @@ -435,13 +436,13 @@ public CoverageResult getPreviousResult() {
if (owner == null) {
return null;
}
Run<?, ?> prevBuild = owner.getPreviousNotFailedBuild();
AbstractBuild<?, ?> prevBuild = BuildUtils.getPreviousNotFailedCompletedBuild(owner);
if (prevBuild == null) {
return null;
}
CoberturaBuildAction action = null;
while ((prevBuild != null) && (null == (action = prevBuild.getAction(CoberturaBuildAction.class)))) {
prevBuild = prevBuild.getPreviousNotFailedBuild();
prevBuild = BuildUtils.getPreviousNotFailedCompletedBuild(prevBuild);
}
if (action == null) {
return null;
Expand Down
Expand Up @@ -6,7 +6,10 @@ xml.report.pattern.description=\
workspace root. Note that the module root is SCM-specific, and may \
not be the same as the workspace root. \
<br/> \
Cobertura must be configured to generate XML reports for this plugin to function.
Cobertura must be configured to generate XML reports for this plugin to function. \
<br/> \
NOTE: If concurrent builds are enabled for this job, and a later build finishes \
before an earlier build, the later build will reduce or skip trend analysis/charting.
only.stable.builds.description=Include only stable builds, i.e. exclude unstable and failed ones.
unhealthy.fail.builds.description=Unhealthy projects will be failed.
unstable.fail.builds.description=Unstable projects will be failed.
Expand All @@ -17,4 +20,4 @@ maxbuilds.coverage.chart.description=Only graph the most recent N builds in the
metric.targets.description=Configure health reporting thresholds. <br/> For the <img src\="{0}/images/16x16/health-80plus.gif" alt\="100%" /> row, leave blank to use the default value (i.e. 80). <br/> For the <img src\="{0}/images/16x16/health-00to19.gif" alt\="0%" /> and <img src\="{0}/images/16x16/yellow.gif" alt\="0%" /> rows, leave blank to use the default values (i.e. 0).

source.encoding.description=Encoding when showing files.
no.reorts.fail.builds.description=fail builds if No coverage reports are found.
no.reorts.fail.builds.description=fail builds if No coverage reports are found.
Expand Up @@ -63,6 +63,7 @@ public HealthReport getBuildHealth()
EasyMock.expect( build.getAction( CoberturaBuildAction.class ) ).andReturn( action ).anyTimes();
EasyMock.expect( build.getDisplayName() ).andReturn( "#" + String.valueOf( c ) ).anyTimes();
EasyMock.expect( build.getPreviousNotFailedBuild() ).andReturn( prevBuild ).anyTimes();
EasyMock.expect( build.isBuilding() ).andReturn( false ).anyTimes();

result.setOwner( build );

Expand Down

0 comments on commit 30e5b57

Please sign in to comment.