Groovy is a popular object-oriented programming language for the Java platform.
In my case, groovy is used as a pipeline scripting language in Jenkins.
A Jenkins Declarative Pipeline script is structured as a hierarchical block-based Groovy Domain Specific Language (DSL).
pipeline { ... }
The mandatory root block that encapsulates the entire definition of the CI/CD workflow.
agent
Defines where the pipeline or specific stage will execute. It specifies whether the job runs on any available executor (agent any), a specific node label (agent { label 'linux' }), or inside a container (agent { docker { image 'python:3.11' } }).
In my case, right now, I have the agent defined as "any".
environment
Declares key-value pairs for environment variables that remain accessible across all stages, useful for paths, credentials IDs, or build flags.
This is often tailored specific to projects and their needs.
stages and stage
The sequential layout of the workflow. The plural stages container holds multiple individual stage blocks (e.g., Checkout, Build, Test, Deploy), each labeled with a human-readable name shown in the Jenkins UI.
In one case of my setup, a stage is labeled 'Checkout Code'. This is where the script performs the git branch checkout for building.
steps
The imperative block inside a stage containing the actual commands and functions executed sequentially (e.g., executing shell scripts via sh, running unit tests, or calling custom shared library functions like publishTestResults).
Example:
steps {
script {
try {
sh '''
. venv/bin/activate
pytest --junitxml=test-results.xml
'''
// If pytest succeeds completely
if (currentBuild.result == null) {
currentBuild.result = 'SUCCESS'
}
...
post
Conditional execution blocks evaluated after the stages complete. It contains conditions such as always, success, failure, or unstable, making it the standard location for archiving artifacts, sending notifications, or publishing test telemetry to InfluxDB.
So what does this mean?
Because it's a script, it can be imported, and "libraries" should be able to be added. This means that a unifying reporting system can be written to filter the results from pytest, gtest, and robotframework in one system. This simplifies reporting data to the influxDB and then displaying in grafana.
A unified reporting structure for any organization can result in consistent data reporting.
Beyond that, output can be tailored for consumption at all levels in an organization on exposed dashboards based on the needs of the views:
- A CEO might only be concerned about trends and completions matching plans.
- A developer might only care about specific test cases that might be failing.
- A CI/CD guy might be concerned about trends of resource utilization (RAM, time, drive space, code size, etc...)
In my case
The plan now is to write unifying code that can be shared across build projects and report consistent SUCCESS, FAILURE, UNSTABLE results as well as test case results.