Class SimpleReferenceRecorder
- All Implemented Interfaces:
ExtensionPoint
,Describable<Publisher>
,BuildStep
,SimpleBuildStep
- Direct Known Subclasses:
ReferenceRecorder
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 ClassesModifier and TypeClassDescriptionstatic class
Descriptor for this step: defines the context and the UI data binding and validation.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
ConstructorsModifierConstructorDescriptionCreates a new instance ofSimpleReferenceRecorder
.protected
SimpleReferenceRecorder
(io.jenkins.plugins.util.JenkinsFacade jenkins) Creates a new instance ofReferenceRecorder
. -
Method Summary
Modifier and TypeMethodDescriptionprotected ReferenceBuild
createEmptyReferenceBuild
(Run<?, ?> run, edu.hm.hafner.util.FilteredLog messages) Finds a job with the given name.protected ReferenceBuild
findReferenceBuild
(Run<?, ?> run, edu.hm.hafner.util.FilteredLog log) getLastBuild
(Job<?, ?> reference) Returns the last build of the specified reference job.protected Optional
<ReferenceBuild> getReferenceBuildWithRequiredStatus
(Run<?, ?> run, Run<?, ?> start, edu.hm.hafner.util.FilteredLog log) Returns a reference build that satisfied the required status.Returns the name of the reference job.protected boolean
hasRequiredResult
(Run<?, ?> referenceBuild) Returns whether the specified build has a result that is better or equal than the required result.boolean
protected void
logNoBuildFound
(Job<?, ?> reference, edu.hm.hafner.util.FilteredLog log) void
protected Object
Called after deserialization to retain backward compatibility.resolveReferenceJob
(edu.hm.hafner.util.FilteredLog log) Finds a reference job that should be used as a starting point to find the reference build.void
setConsiderRunningBuild
(boolean considerRunningBuild) If enabled, then running builds will be considered as reference build as well.void
setReferenceJob
(String referenceJob) Sets the reference job: this job will be used as a baseline to search for the best matching reference build.void
setRequiredResult
(Result requiredResult) Sets that required build result of the reference build.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
-
SimpleReferenceRecorder
@DataBoundConstructor public SimpleReferenceRecorder()Creates a new instance ofSimpleReferenceRecorder
. -
SimpleReferenceRecorder
protected SimpleReferenceRecorder(io.jenkins.plugins.util.JenkinsFacade jenkins) Creates a new instance ofReferenceRecorder
.- Parameters:
jenkins
- facade to Jenkins
-
-
Method Details
-
readResolve
Called after deserialization to retain backward compatibility.- Returns:
- this
-
setReferenceJob
Sets the reference job: this job will be used as a baseline to search for the best matching reference build. If the reference job should be computed automatically (supported bymulti-branch projects
only), then let this field empty. If the reference job is not defined and cannot be computed automatically, then the current job will be used.- Parameters:
referenceJob
- the name of reference job
-
getReferenceJob
Returns the name of the reference job.- Returns:
- the name of reference job
-
setRequiredResult
Sets that required build result of the reference build. If the reference build has a worse status, then the selected reference build will not be used.- Parameters:
requiredResult
- the minimum required build result
-
getRequiredResult
-
hasRequiredResult
Returns whether the specified build has a result that is better or equal than the required result.- Parameters:
referenceBuild
- the reference build to check- Returns:
true
if the build has a result that is better or equal than the required result,false
otherwise
-
getRequiredMonitorService
- Specified by:
getRequiredMonitorService
in interfaceBuildStep
-
getDescriptor
- Specified by:
getDescriptor
in interfaceDescribable<Publisher>
- Overrides:
getDescriptor
in classRecorder
-
perform
public void perform(@NonNull Run<?, ?> run, @NonNull FilePath workspace, @NonNull EnvVars env, @NonNull Launcher launcher, @NonNull TaskListener listener) - Specified by:
perform
in interfaceSimpleBuildStep
-
setConsiderRunningBuild
@DataBoundSetter public void setConsiderRunningBuild(boolean considerRunningBuild) 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.- Parameters:
considerRunningBuild
- iftrue
then running builds will be considered as reference build as well
-
isConsiderRunningBuild
public boolean isConsiderRunningBuild() -
findReferenceBuild
-
logNoBuildFound
-
getReferenceBuildWithRequiredStatus
protected Optional<ReferenceBuild> getReferenceBuildWithRequiredStatus(Run<?, ?> run, Run<?, ?> start, edu.hm.hafner.util.FilteredLog log) Returns a reference build that satisfied the required status. Starting with the specifiedstart
build, the history of builds is searched for a build that satisfies the required status. If no such build is found, then a null object is returned.- Parameters:
run
- the run that is currently builtstart
- the first build to start the searchlog
- the logger- Returns:
- the reference build that satisfies the required status (or empty if no such build is found)
-
createEmptyReferenceBuild
protected ReferenceBuild createEmptyReferenceBuild(Run<?, ?> run, edu.hm.hafner.util.FilteredLog messages) -
resolveReferenceJob
Finds a reference job that should be used as a starting point to find the reference build.- Parameters:
log
- the logger- Returns:
- the reference job (if available)
-
findJob
Finds a job with the given name.- Parameters:
jobName
- the name of the joblog
- the logger- Returns:
- the job with the given name (if existing)
-
getLastBuild
Returns the last build of the specified reference job. If the reference build is not completed and the optionconsiderRunningBuild
is set, then the last running build is returned. Otherwise, the last completed build is returned.- Parameters:
reference
- the reference job- Returns:
- the last build of the reference job
-