Scrivio Interview library
DesignFoundations6 min read · updated 12 November 2026

Describe a CI pipeline for a Spring Boot service from pull request to a deployable artifact.

On every pull request the pipeline checks out the code, sets up a pinned JDK, restores the dependency cache and runs mvn verify or gradle build, which compiles, runs unit and integration tests and static analysis, then publishes test and coverage reports and fails on quality gate violations. On main it then builds the container image once, scans it, signs it and pushes it with an immutable tag. That same artifact is deployed through every environment, never rebuilt.

Why this question is asked

A CI pipeline is the path every line of code takes to production, so its design decides how fast we get feedback, how much we can trust a green build, and whether what we deploy is really what we tested. Interviewers ask this to see whether we know the stages and, more importantly, the reasons behind them: why pin the JDK, why build the image only once, why deploy by digest. In this answer, we will walk through the pipeline stage by stage, show a compact GitHub Actions example, and explain the principle of promoting one artifact.

1A Quick Recap of the Goal

Continuous integration means every change is built and tested automatically as soon as it is pushed, so problems are found within minutes rather than days. For a Spring Boot service, the end product of the pipeline is a deployable artifact: today usually an OCI container image, the standard image format that Docker and Kubernetes use, containing the application and a Java runtime.

The pipeline has two modes. On a pull request it answers one question, is this change safe to merge, as fast as possible. On main it also produces the artifact that will go to production. Both run the same build steps, so a change that passed on its pull request behaves the same after merging.

2Setting Up: Checkout, Pinned JDK, Cache

The first stage prepares a clean, predictable environment. The pipeline checks out the exact commit. It installs a pinned JDK version and distribution, for example Temurin 25, rather than whatever the build agent happens to have, so the build is the same on every agent and every month. It restores the dependency cache, the downloaded Maven or Gradle dependencies, keyed on a hash of the build files, which often saves one or two minutes per run. The Maven Wrapper or Gradle Wrapper also pins the build tool version, which matters just as much.

3Building, Testing and Analysing

Next comes the main build. For Maven, mvn verify runs the lifecycle up to verify: compile, unit tests with Surefire, packaging, integration tests with Failsafe, and any analysis bound to verify, such as Error Prone during compilation, SpotBugs, Checkstyle or a coverage check with JaCoCo. For Gradle, gradle build does the equivalent. Integration tests for a Spring Boot service usually use Testcontainers to start a real PostgreSQL or Kafka in Docker.

Then we publish the results: JUnit reports so failures show up in the pull request, coverage reports, and analysis results, for example to SonarQube. A quality gate, a set of thresholds such as no new critical issues and at least 80 percent coverage on new code, fails the pipeline if it is not met. Failing on new code rather than the whole code base keeps the gate fair for old projects.

YAML
# .github/workflows/ci.yml (simplified)
on: [pull_request, push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with: { distribution: temurin, java-version: '25', cache: maven } # pinned JDK + dependency cache
- run: ./mvnw -B verify # compile, unit + integration tests, analysis
- uses: actions/upload-artifact@v4
if: always() # keep reports even when tests fail
with: { name: reports, path: '**/target/*-reports/' }
image:
needs: build
if: github.ref == 'refs/heads/main' # only main produces a deployable artifact
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./mvnw -B spring-boot:build-image -DskipTests -Dspring-boot.build-image.imageName=$IMAGE:$GITHUB_SHA
- run: trivy image --exit-code 1 --severity CRITICAL $IMAGE:$GITHUB_SHA # scan, fail on critical
- run: docker push $IMAGE:$GITHUB_SHA
- run: cosign sign --yes $IMAGE@$DIGEST # sign the pushed digest

Notice that tests are skipped in the image job only because the build job, which it depends on, already ran them on the same commit. Action versions and tool names here are examples; pin them to versions your organisation approves, and check each tool's current flags.

4On Main: Build the Image Once, Scan, Sign, Push

When the change reaches main, the pipeline builds the container image. Spring Boot can do this without a Dockerfile, using Cloud Native Buildpacks through spring-boot:build-image or bootBuildImage, or we can use Jib or a Dockerfile with a layered jar. We also generate an SBOM, a software bill of materials listing every library in the image, for example with the CycloneDX plugin, so we can answer later which services contain a vulnerable library.

The image is scanned for known vulnerabilities with a tool such as Trivy or Grype, and the pipeline fails on findings above an agreed severity. It is then pushed to the registry with an immutable tag, typically the git commit SHA, never only latest, and signed, for example with cosign, so the deployment platform can verify it came from our pipeline. The registry returns a digest, sha256:..., which identifies exactly these bytes.

Step throughFrom pull request to deployable artifact
  1. Checkout, pinned JDK, cacheTemurin 25, Maven Wrapper, cache by POM hash
  2. mvn verifycompile, unit and integration tests, analysis
  3. Reports and quality gateJUnit, coverage, Sonar; fail on new issues
  4. Is this main?
    YesBuild the imageNoStop: PR result reported
  5. Build image once, SBOMbuildpacks or Jib, tag = commit SHA
  6. Scan, sign, pushfail on critical CVEs, cosign, record digest
  7. Promote the same digestdev -> staging -> production

7 steps in order. Play them, or step through them one at a time.

Pull requests stop after the quality gate; main continues to a signed image.

5Deploying the Same Artifact Everywhere

The last principle is the most important: build once, deploy many. The exact image digest that passed the tests is deployed to the development environment, then promoted to staging and production. We never rebuild for production, because a rebuild can pick up a different base image or dependency, and then what we deploy is not what we tested. Differences between environments come from configuration, such as environment variables, Spring profiles or a config server, not from different builds. Deploying by digest rather than by tag also guarantees that nobody can change what a tag points to between staging and production.

6Follow-up questions

Should integration tests run on every pull request?

Yes, if they are fast enough, typically when the whole pipeline stays under about ten to fifteen minutes. If they are slow, split them: run unit tests and the most important integration tests on the pull request, and the full suite on main or before deployment. Slow pipelines encourage large, infrequent merges, which is worse.

Why not build the jar on the pull request and reuse it?

Some pipelines do pass the built jar to the image job as an artifact, which saves time. The important rule is only that the artifact deployed is the one that was tested; whether the image is built in the same job or from a stored jar is an optimisation.

Where should secrets for the pipeline live?

In the CI system's secret store or, better, obtained at run time through short-lived credentials such as OIDC federation to the cloud provider, never in the repository. Pull requests from forks should not get access to secrets at all.

7Conclusion

In this answer, we built a CI pipeline for a Spring Boot service: checkout, a pinned JDK and a restored dependency cache; mvn verify or gradle build with unit tests, integration tests and static analysis; published reports and a quality gate; then on main a container image built once, scanned, signed and pushed with an immutable tag, and that same artifact promoted through every environment.

What to say in the interviewAbout 80 seconds aloud

Open with

I would describe it in two halves. Every pull request runs the same first half: check out the commit, set up a pinned JDK, say Temurin 25, through setup-java or a toolchain, use the Maven or Gradle wrapper so the build tool is pinned too, and restore the dependency cache keyed on the build files.

Then, if they want more

Then mvn verify, which compiles with checks like Error Prone, runs unit tests with Surefire and integration tests with Failsafe and Testcontainers, and runs static analysis. The pipeline publishes test and coverage reports and applies a quality gate, usually on new code, and fails if it is not met.

When the change lands on main, the second half runs: build the container image exactly once, for example with Spring Boot buildpacks or Jib, generate an SBOM, scan the image with Trivy or Grype and fail on critical findings, push it with the commit SHA as an immutable tag, and sign the digest with cosign.

From then on we never rebuild. The same digest is deployed to dev, promoted to staging and then production, with only configuration differing, so what runs in production is exactly what we tested.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Describe a CI pipeline for a Spring Boot service from pull request to a deployable...": https://scrivio-interview-library.netlify.app/java/version-control-and-ci/beec0604b8/