Skip to content

Commit

Permalink
[JENKINS-73380] Add an option to consider running builds as reference.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Aug 19, 2024
1 parent 4f5b2e3 commit 48c1468
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.jenkinsci.Symbol;
import hudson.Extension;
import hudson.model.Run;
import jenkins.scm.api.SCMHead;

import io.jenkins.plugins.forensics.reference.ReferenceRecorder;
import io.jenkins.plugins.util.JenkinsFacade;
Expand Down Expand Up @@ -78,8 +77,7 @@ public boolean isSkipUnknownCommits() {
@Override
protected Optional<Run<?, ?>> find(final Run<?, ?> owner, final Run<?, ?> lastCompletedBuildOfReferenceJob,
final FilteredLog log) {
Optional<GitCommitsRecord> referenceCommit
= GitCommitsRecord.findRecordForScm(lastCompletedBuildOfReferenceJob, getScm());
var referenceCommit = GitCommitsRecord.findRecordForScm(lastCompletedBuildOfReferenceJob, getScm());

Optional<Run<?, ?>> referenceBuild;
if (referenceCommit.isPresent()) {
Expand All @@ -95,7 +93,7 @@ public boolean isSkipUnknownCommits() {
return referenceBuild;
}

Optional<SCMHead> targetBranchHead = findTargetBranchHead(owner.getParent());
var targetBranchHead = findTargetBranchHead(owner.getParent());
if (targetBranchHead.isPresent()) {
log.logInfo("-> falling back to latest build '%s' since a pull or merge request has been detected",
lastCompletedBuildOfReferenceJob.getDisplayName());
Expand All @@ -108,13 +106,12 @@ public boolean isSkipUnknownCommits() {

private Optional<Run<?, ?>> findByCommits(final Run<?, ?> owner, final GitCommitsRecord referenceCommit,
final FilteredLog log) {
Optional<GitCommitsRecord> ownerCommits = GitCommitsRecord.findRecordForScm(owner, getScm());
var ownerCommits = GitCommitsRecord.findRecordForScm(owner, getScm());
if (ownerCommits.isPresent()) {
GitCommitsRecord commitsRecord = ownerCommits.get();
Optional<Run<?, ?>> referencePoint = commitsRecord.getReferencePoint(
referenceCommit, getMaxCommits(), isSkipUnknownCommits(), log);
var commitsRecord = ownerCommits.get();
var referencePoint = commitsRecord.getReferencePoint(referenceCommit, getMaxCommits(), isSkipUnknownCommits(), log);
if (referencePoint.isPresent()) {
Run<?, ?> referenceBuild = referencePoint.get();
var referenceBuild = referencePoint.get();
log.logInfo("-> found build '%s' in reference job with matching commits",
referenceBuild.getDisplayName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
<f:number default="100"/>
</f:entry>

<f:entry field="skipUnknownCommits">
<f:checkbox title="${%title.skipUnknownCommits}"/>
<f:entry field="skipUnknownCommits" title="${%title.skipUnknownCommits}">
<f:checkbox />
</f:entry>

<f:entry field="latestBuildIfNotFound">
<f:checkbox title="${%title.latestBuildIfNotFound}"/>
<f:entry field="latestBuildIfNotFound" title="${%title.latestBuildIfNotFound}">
<f:checkbox />
</f:entry>

<f:entry title="${%title.considerRunningBuild}" field="considerRunningBuild">
<f:checkbox />
</f:entry>

</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ description.maxCommits=Defines how many commits of a job''s Git history should b
title.targetBranch=Target Branch
title.skipUnknownCommits=Ignore reference job builds with commits that are not part of the current build
title.latestBuildIfNotFound=Fallback to the latest-completed build if no reference build has been found
title.considerRunningBuild=Consider running builds as reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
If enabled, then running builds will be considered as reference build as well. Otherwise, only completed builds
are considered. Enabling this option might cause problems if the reference build has not yet all the
required results available.

0 comments on commit 48c1468

Please sign in to comment.