Class ReferenceRecorder
- All Implemented Interfaces:
ExtensionPoint
,Describable<Publisher>
,BuildStep
,SimpleBuildStep
Several plugins that report build statistics (test results, code coverage, metrics, static analysis warnings) typically show their reports in two different ways: either as absolute report (e.g., total number of tests or warnings, overall code coverage) or as relative delta report (e.g., additional tests, increased or decreased coverage, new or fixed warnings). To compute a relative delta report, a plugin needs to carefully select the other build to compare the current results to (a so-called reference build). For simple Jenkins jobs that build the main branch of an SCM, the reference build will be selected from one of the previous builds of the same job. For more complex branch source projects (i.e., projects that build several branches and pull requests in a connected job hierarchy) it makes more sense to select a reference build from a job that builds the actual target branch (i.e., the branch the current changes will be merged into). Here one typically is interested what changed in a branch or pull request with respect to the main branch (or any other target branch): e.g., how will the code coverage change if the team merges the changes. Selecting the correct reference build is not that easy, since the main branch of a project will evolve more frequently than a specific feature or bugfix branch.
This recorder unifies the computation of the reference build so consuming plugins can simply use the resulting ReferenceBuild
in order to get a reference for their delta reports.
- Author:
- Arne Schöntag, Ullrich Hafner
-
Nested Class Summary
Nested classes/interfaces inherited from class io.jenkins.plugins.forensics.reference.SimpleReferenceRecorder
SimpleReferenceRecorder.SimpleReferenceRecorderDescriptor
Nested classes/interfaces inherited from class hudson.tasks.Publisher
Publisher.DescriptorExtensionListImpl
Nested classes/interfaces inherited from interface hudson.tasks.BuildStep
BuildStep.PublisherList
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
Nested classes/interfaces inherited from interface jenkins.tasks.SimpleBuildStep
SimpleBuildStep.LastBuildAction, SimpleBuildStep.LastBuildActionFactory
-
Field Summary
Fields inherited from interface hudson.tasks.BuildStep
BUILDERS, PUBLISHERS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Creates a new instance ofReferenceRecorder
.protected
ReferenceRecorder
(io.jenkins.plugins.util.JenkinsFacade jenkins) Creates a new instance ofReferenceRecorder
. -
Method Summary
Modifier and TypeMethodDescriptionfind
(Run<?, ?> owner, Run<?, ?> lastCompletedBuildOfReferenceJob, edu.hm.hafner.util.FilteredLog logger) Returns the reference build for the given buildowner
.protected ReferenceBuild
findReferenceBuild
(Run<?, ?> run, edu.hm.hafner.util.FilteredLog logger) protected Optional
<jenkins.scm.api.SCMHead> findTargetBranchHead
(Job<?, ?> job) getScm()
boolean
void
setLatestBuildIfNotFound
(boolean latestBuildIfNotFound) If enabled, then the latest build of the reference job will be used if no other reference build has been found.void
Sets the SCM that should be used to find the reference build for.void
setTargetBranch
(String targetBranch) Sets the target branch formulti-branch projects
: the target branch is considered the base branch in your repository.Methods inherited from class io.jenkins.plugins.forensics.reference.SimpleReferenceRecorder
createEmptyReferenceBuild, findJob, getDescriptor, getLastBuild, getReferenceBuildWithRequiredStatus, getReferenceJob, getRequiredMonitorService, getRequiredResult, hasRequiredResult, isConsiderRunningBuild, logNoBuildFound, perform, readResolve, resolveReferenceJob, setConsiderRunningBuild, setReferenceJob, setRequiredResult
Methods inherited from class hudson.tasks.Publisher
all, getProjectAction, needsToRunAfterFinalized, prebuild
Methods inherited from class hudson.tasks.BuildStepCompatibilityLayer
getProjectAction, getProjectActions, perform, perform, prebuild
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface hudson.tasks.BuildStep
getProjectAction, getProjectActions, perform, prebuild
Methods inherited from interface jenkins.tasks.SimpleBuildStep
perform, perform, requiresWorkspace
-
Constructor Details
-
ReferenceRecorder
protected ReferenceRecorder()Creates a new instance ofReferenceRecorder
. -
ReferenceRecorder
protected ReferenceRecorder(io.jenkins.plugins.util.JenkinsFacade jenkins) Creates a new instance ofReferenceRecorder
.- Parameters:
jenkins
- facade to Jenkins
-
-
Method Details
-
setLatestBuildIfNotFound
@DataBoundSetter public void setLatestBuildIfNotFound(boolean latestBuildIfNotFound) If enabled, then the latest build of the reference job will be used if no other reference build has been found.- Parameters:
latestBuildIfNotFound
- iftrue
then the latest build of the reference job will be used if no matching reference build has been found, otherwise no reference build is returned.
-
isLatestBuildIfNotFound
public boolean isLatestBuildIfNotFound() -
setTargetBranch
Sets the target branch formulti-branch projects
: the target branch is considered the base branch in your repository. The builds of all other branches and pull requests will use this target branch as baseline to search for a matching reference build.- Parameters:
targetBranch
- the name of the default branch
-
getTargetBranch
-
setScm
Sets the SCM that should be used to find the reference build for. The reference recorder will select the SCM based on a substring comparison, there is no need to specify the full name.- Parameters:
scm
- the ID of the SCM to use (a substring of the full ID)
-
getScm
-
findReferenceBuild
- Overrides:
findReferenceBuild
in classSimpleReferenceRecorder
-
findTargetBranchHead
-
find
protected Optional<Run<?,?>> find(Run<?, ?> owner, Run<?, ?> lastCompletedBuildOfReferenceJob, edu.hm.hafner.util.FilteredLog logger) Returns the reference build for the given buildowner
. The search should start with the last completed build of the reference build. This default implementation does nothing.- Parameters:
owner
- the owner to get the reference build forlastCompletedBuildOfReferenceJob
- the last completed build of the reference joblogger
- the logger to use- Returns:
- the reference build (if available)
-