Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-73380] Add option to consider running builds as reference #814

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.