The problem. Most software teams pass every code change through an
automated build before it is merged into the main code. In Jenkins, a common build
server, these builds often measure useful things, such as how much of the code is
tested, but only report the result. A change that adds untested code or new
code-quality problems can still be merged. Large projects also rebuild everything for
every small change, so builds are slow.
What I built. A small shared add-on for Jenkins that turns those
reports into a clear pass or block decision for every change, and a script that works
out which parts of a large project a change affects, so only those parts are
rebuilt.
How I tested it. On two public open-source Java projects, built on my
own Jenkins. One is a large project made of 43 parts, whose
own build had the problems above. The other is a small web application, where I made
test changes, each designed to trip one specific check.
What I found. Every test change received the decision it should
have. For a change to one service in the large project, only
3 of its 43 parts needed
rebuilding. My first timing comparison overstated the speed gain; a fairer re-run
showed a much smaller difference, within the normal spread between runs, so I
withdrew that claim.
If you only have a minute, stop here. Each section below shows
the build records behind these statements.
Try it. Three test changes I made to the web
application, and what the merge check decided for each. Select one.
Why 92% and 0% at once?
The application's existing code is well tested. The few lines the untested change
adds have no test at all. A check on the whole-application figure alone would let that
change through; the second check exists for exactly that.
Why "already on main"?
The main code already had 1 code-quality warning
before any of my changes. The check counts only warnings a change adds, so an
old problem never blocks unrelated work.
Why is the warning change 100% tested?
Each test change trips one check only. Its new lines are tested, so the only thing
blocking it is the one warning it adds.
Section 1
The two test projects, and how they were run
I needed one project with a genuinely poor build to fix, and one with a
real pull-request workflow to test the merge check on. No single public project had
both.
Train-Ticket
The large project · 43 parts
An open-source train-booking system from Fudan University researchers, built with
Maven, the standard Java build tool. Its own Jenkins build had the problems in
section 2. Fixed to commit 313886e, so every run builds the same code.
Spring PetClinic
The small project · test changes
The official sample web application for the Spring Java framework. Small and well
tested, so the right outcome of each test change is known in advance.
The shared check
One add-on, both projects
A Jenkins shared library: code that many build files can call. Both projects call
the same library; each sets its own limits.
Where the numbers come from. Everything ran on a
Jenkins server in Docker on my own machine. After each build, its results were exported
from Jenkins to JSON files, and this page is generated from those files. Every measured
figure is generated from those files; the 90% and 80% limits are the settings in the
build file shown in section 7. Each figure names the build and the file it came from.
Section 2
What was wrong with the original build
Train-Ticket's own Jenkins build, run unchanged, had four problems this kit
fixes and three more worth knowing about. Each card quotes the line of the build file
that shows it.
Show 3 more findings
Section 3
How the merge check decides
Every pull request (a proposed change waiting to be merged) runs through
three checks in order. If any one fails, the change is blocked.
Is the whole application still tested? The share of all code lines
that the tests run, measured by JaCoCo. It must stay at or above 90%.
Is this change tested? The share of the lines this pull request
changed that the tests run. It must be at least 80%.
Does this change add code-quality warnings? PMD, a static checker,
reads the code for likely bugs and bad patterns without running it. A change may not
add any new warning; existing ones are ignored.
A documentation-only change has no code lines to measure; the check
records that and passes it.
What you are looking at: the two test changes that should be blocked, each
by a different check, with the values Jenkins recorded.
The same builds as Jenkins shows them. Select a screenshot to open it at
full size.
All seven test builds, with their full records
I ran the untested change and the warning change twice each, and got
the same result both times. The main branch build is the reference every change is
compared against.
Earlier check runs on Train-Ticket (whole-project coverage only)
Section 4
Rebuilding only what a change touches
Train-Ticket is made of 43 parts that Maven
builds together. Normally every change rebuilds all of them. My script reads which files
a change touched, picks the parts that contain them plus the parts connected to those,
and builds only that set. When it cannot be sure, it builds everything.
What you are looking at: each square is one part of Train-Ticket. Pick a
kind of change to see which parts the script would build.
--of --
Diagram only: highlighted squares show how many parts are
built, not which ones.
For a change to one service, 3 parts and
51 tests ran in 38.2
seconds, against all 43 parts for a full build. This shows the
scope one known change needs. It is not an average build time.
Script output for every kind of change
Wide console capture. Scroll sideways to read it.
Section 5
Build timings, and the claim I withdrew
I built the whole of Train-Ticket nine times
on my Jenkins: three times with the original build, three with my new build, and three
with my new build made to package every part, as the original does.
My first comparison showed the new build 38.9% faster. That was not a fair test. Many of Train-Ticket's own tests fail before I change anything: 220 of 626 failed or errored in my baseline builds. A separate run of the untouched project recorded 221; one login test behaves differently between runs, and I have not proven why. My new build stops at any part whose tests fail, so only 11 of the 43 parts were packaged, while the original packaged all of them. When I made the new build package every part, it was 12.6% faster at the median, and its three runs overlapped with the original's. Even then the work is not identical: the original also installs every part in a separate step. So I do not claim a speed-up.
What you are looking at: each dot is one full build. The dashed line is
the middle of three builds; the grey line runs from the fastest to the slowest.
Original: Train-Ticket's own build. New: my build. New +
packaging: my build forced to package every part, like the original.
Open a build record
Select a build above, or a dot on the chart, to see its time, result
and command as Jenkins recorded them.
All nine builds as a table
Section 6
Mistakes I found and fixed
After the first results, I re-checked my own work. These things were wrong
or overstated. Each card says what was wrong, why it mattered, and what I changed. The
original records are kept, not edited.
Section 7
Trying this on a real team's pipeline
This is a tested proof of concept, not a production rollout. A team trying
it would start small:
Pick one repository and run the check in report-only mode, so it records decisions
without blocking anything.
Install the Jenkins plugins it relies on (JUnit, Coverage, Warnings NG and Git
Forensics) and add the library as a trusted shared library, fixed to one release.
Choose its own limits. 80% of changed lines tested is my choice for this
demonstration, not a recommendation.
Switch to blocking once the recorded decisions match what reviewers would have
decided.
Not tested here: Bitbucket or any hosted Git server (I
used a local Git server), cloud or container build agents, many builds at once,
deployment, and security testing.
A project uses the check by adding one line to its Jenkins build file
and one step at the end:
@Library('prk@lib-v1.1.1') _
Show the build file used for the test changes (examples/Jenkinsfile.multibranch)
make up # start the pinned Jenkins stack
make verify # run the harness checks
make demo # build main first, then every test change
Needs Docker Desktop, Python 3 and Git. Works from a fresh clone.
Section 8
Evidence and limits
For readers who want to check the work.
What I do not claim
No speed-up for the same amount of work.
Not production-ready, not proven on every kind of project, and no guaranteed
build-time saving.
Train-Ticket's own tests do not all pass; the project already had failing tests.
No security scanning of any kind.
Show build conditions
Show automated checksShow recorded limits
Quoted as written in the evidence files at the time, with the file
each came from. Lines later made out of date by further work are left out. One line
later found to be wrong is shown with its correction.
Show every source file
Every record carries its source JSON. The page generator rejects
missing files, missing fields, mismatched medians and invalid percentages.