The ReasonToBuildDocumentation custom Groovy task analyzes and documents the reason why each file was built during a zBuilder build. It distinguishes between files that were built because they were changed versus files that were built due to dependencies (impacted files). This information is captured in the DBB Build Report as metadata records and can be used for analysis, reporting, and testing decisions.
| Folder/File | Description |
|---|---|
| groovy/documentReasonToBuild.groovy | Groovy script that implements the logic for analyzing and documenting build reasons. |
- Clone this DBB Community Repository to your workstation.
- Copy the
documentReasonToBuild.groovyscript to the$DBB_BUILD/groovydirectory.
Note: The Groovy script must reside in the
$DBB_BUILD/groovysubdirectory to be automatically discovered by the task configuration.
Add the ReasonToBuildDocumentation task to your dbb-build.yaml configuration. The task should be placed in the impact lifecycle after the Languages task. The Languages task is responsible for populating the BUILD_LIST context variable, which is required by this task to document build reasons.
Example dbb-build.yaml configuration:
lifecycles:
- lifecycle: impact
tasks:
- Start
- ScannerInit
- MetadataInit
- ImpactAnalysis
- Languages # Defined in Languages.yaml
- ReasonToBuildDocumentation # Document build reasons
- Finish
tasks:
- task: ReasonToBuildDocumentation
script: groovy/documentReasonToBuild.groovyThe documentReasonToBuild.groovy script performs the following:
- Retrieves Build Context: Reads the
CHANGED_FILESandBUILD_LISTcontext variables populated by theImpactAnalysistask. - Categorizes Files:
- Changed Files: Files that were modified and are on the
CHANGED_FILESlist. - Impacted Files: Files that are on the
BUILD_LISTbut not on theCHANGED_FILESlist (built due to dependencies).
- Changed Files: Files that were modified and are on the
- Generates Metadata Records: Creates a
PropertiesRecordfor each file in the build list with two properties:file: The file pathreasonForBuilding: Either "changed" or "impacted"
- Provides Reporting: In verbose mode, displays detailed statistics including:
- List of changed files
- List of impacted files
- Summary statistics (total changed, total built, impacted count)
For each file in the build list, a PropertiesRecord is added to the DBB Build Report with the following structure:
PropertiesRecord:
- file: "MortgageApplication/cobol/epscmort.cbl"
- reasonForBuilding: "changed"
When running in verbose mode (--verbose flag), the task provides detailed output:
> Document reason for building
=== Build Analysis Report ===
==================================================
> Changed Files: 2
--------------------------------------------------
MortgageApplication/cobol/epscmort.cbl
MortgageApplication/cobol/epsmlist.cbl
> Impacted Files (built due to dependencies): 1
--------------------------------------------------
MortgageApplication/cobol/epsmpmt.cbl
=== Summary ===
--------------------------------------------------
Total Changed Files: 2
Total Files Built: 3
Impacted Files: 1
Changed & Built: 2
==================================================
This task consumes the following context variables:
CHANGED_FILES: Set of files that were modified (populated by theImpactAnalysistask)BUILD_LIST: Set of files that were built (populated by the Languages task)
Important: This task must run after both:
- The
ImpactAnalysistask (which populatesCHANGED_FILES) - The
Languagestask (which populatesBUILD_LISTwith all source files built by executed language configurations)
The Languages task is a recommended prerequisite that executes all configured language build tasks and aggregates the built files into the BUILD_LIST context variable.
- The task is compatible with DBB's build report system and integrates seamlessly into the
impactlifecycle. - Metadata records generated by this task can be consumed by downstream processes such as packaging scripts and deployment tools.
- The task has no impact on the actual build process; it only adds documentation to the build report.
- In non-verbose mode, only summary counts are displayed to minimize console output.