Skip to content
Permalink
Browse files

Merge pull request #6 from jtnord/JENKINS-18931

Fixes Jenkins-18931
  • Loading branch information
gboissinot committed Jul 27, 2013
2 parents 12f65d7 + 51a544d commit f3f5fab993d404e2b18f32e8af1f2ad35981f771
Showing with 9 additions and 7 deletions.
  1. +9 −7 src/main/java/org/jenkinsci/plugins/buildresulttrigger/BuildResultTrigger.java
@@ -101,7 +101,7 @@ protected BuildResultTriggerContext getContext(Node node, XTriggerLog log) throw
for (String jobName : info.getJobNamesAsArray()) {
AbstractProject job = Hudson.getInstance().getItemByFullName(jobName, AbstractProject.class);
if (isValidBuildResultProject(job)) {
Run lastBuild = job.getLastBuild();
Run lastBuild = job.getLastCompletedBuild();
if (lastBuild != null) {
int buildNumber = lastBuild.getNumber();
if (buildNumber != 0) {
@@ -166,7 +166,7 @@ private boolean checkIfModifiedJob(String jobName, CheckedResult[] expectedResul
}

if (newContextResults.size() != oldContextResults.size()) {
return isMatchingExpectedResults(jobName, expectedResults, log);
return isMatchingExpectedResults(jobName, expectedResults, log, newContextResults.get(jobName));
}

Integer newLastBuildNumber = newContextResults.get(jobName);
@@ -178,29 +178,31 @@ private boolean checkIfModifiedJob(String jobName, CheckedResult[] expectedResul

Integer oldLastBuildNumber = oldContextResults.get(jobName);
if (oldLastBuildNumber == null || oldLastBuildNumber.intValue() == 0) {
return isMatchingExpectedResults(jobName, expectedResults, log);
return isMatchingExpectedResults(jobName, expectedResults, log, newContextResults.get(jobName));
}

//Process if there is a new build between now and previous polling
if (newLastBuildNumber.intValue() == 0 || newLastBuildNumber.intValue() != oldLastBuildNumber.intValue()) {
return isMatchingExpectedResults(jobName, expectedResults, log);
return isMatchingExpectedResults(jobName, expectedResults, log, newContextResults.get(jobName));
}

log.info(String.format("There are no new builds for the job %s.", jobName));
return false;
}


private boolean isMatchingExpectedResults(String jobName, CheckedResult[] expectedResults, XTriggerLog log) {
private boolean isMatchingExpectedResults(String jobName, CheckedResult[] expectedResults, XTriggerLog log, Integer buildId) {
log.info(String.format("There is at least one new build for the job %s. Checking expected job build results.", jobName));

if (expectedResults == null || expectedResults.length == 0) {
log.info("No results to check. You have to specify at least one expected build result in the build-result trigger configuration.");
return false;
}

if (buildId == null) {
// no complete build was found so can't trigger here.
}
AbstractProject jobObj = Hudson.getInstance().getItemByFullName(jobName, AbstractProject.class);
Run jobObjLastBuild = jobObj.getLastBuild();
Run jobObjLastBuild = jobObj.getBuildByNumber(buildId.intValue());
Result jobObjectLastResult = jobObjLastBuild.getResult();

for (CheckedResult checkedResult : expectedResults) {

0 comments on commit f3f5fab

Please sign in to comment.
You can’t perform that action at this time.