Cutting Feature Branch Build Time with Caching and Path-Filtered Analysis
You are a DevOps engineer for a company developing a mobile application. The source code is stored in Azure Repos (Git). The team uses trunk-based development with short-lived feature branches. Recently, developers have reported that their feature branch builds are taking over 30 minutes, whereas the main branch builds complete in under 10 minutes. The pipeline is defined in a YAML file and includes steps to restore NuGet packages, compile, run unit tests, and perform code analysis. The pipeline also publishes build artifacts. The main branch has a branch policy that requires a successful build before merging. The feature branches do not have branch policies. All builds run on Microsoft-hosted agents. Upon investigation, you notice that the feature branch builds are restoring all NuGet packages from scratch each time, while main branch builds use cached packages. Additionally, the code analysis tool is scanning the entire codebase, not just the changed files. You need to reduce the feature branch build time to under 15 minutes without compromising code quality. Which course of action should you take?
Quick Answer
The two root causes here — full NuGet restores every run and full-codebase static analysis — need two separate fixes. Enabling pipeline caching via the Cache@2 task persists the NuGet packages folder between runs so restores stop re-downloading everything, and scoping the code analysis step to only changed files with path filters cuts analysis time without skipping real coverage.
⚠ Common exam trap
It's easy for candidates to assume hardware upgrades (larger agents or self-hosted machines) are the solution, when the real issue is inefficient pipeline logic—specifically, missing caching and incremental scanning—which are software-level optimizations that directly target the root causes.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Enable pipeline caching for NuGet packages and configure the code analysis step to scan only changed files using path filters.
It directly addresses the two root causes of the slow feature branch builds: uncached NuGet package restores and full-codebase code analysis. Enabling pipeline caching (using the Cache@2 task) stores the NuGet packages folder (typically ~/.nuget/packages) and restores it on subsequent runs, eliminating redundant downloads. Configuring the code analysis step with path filters (e.g., using the 'changedFiles' condition or a custom script) ensures only modified files are scanned, drastically reducing analysis time without sacrificing quality.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Configure a self-hosted agent with pre-installed dependencies and a larger disk for faster I/O.
Why it's wrong here
Self-hosted agents require maintenance and may not solve the caching or analysis scope issues.
- ✓
Enable pipeline caching for NuGet packages and configure the code analysis step to scan only changed files using path filters.
Why this is correct
Caching reduces restore time, and scanning only changed files reduces analysis time.
- ✗
Remove the code analysis step from feature branch builds and only run it on main branch builds.
Why it's wrong here
This compromises code quality on feature branches.
- ✗
Increase the agent VM size to a more powerful SKU for feature branch builds.
Why it's wrong here
This increases cost and may not address the root causes of cache misses and full code analysis.
Go deeper
Related to this question
Learn chapter
Introduction to DevOps and Azure DevOps
Key term
Git
Git is a version control system that tracks changes to files so multiple people can work on the same project without overwriting each other's work.
Key term
Trunk-based development
Trunk-based development is a version control practice where developers integrate small changes frequently into a single main branch, called the trunk, to avoid merge conflicts and enable continuous delivery.
About these practice questions
One of 823 original AZ-400 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
8 more ways this is tested on AZ-400
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Your team uses Azure Pipelines to build a .NET Core application. You notice that the build takes too long because it restores NuGet packages every time. What is the best way to improve build performance?
easy- A.Configure the build to use a self-hosted agent with previously restored packages
- B.Use a private agent with a faster network connection
- C.Use a Microsoft-hosted agent with a larger SKU
- ✓ D.Enable the 'Cache' task to cache the NuGet packages folder
Why D: The best way to improve build performance is to cache the NuGet packages folder using the 'Cache' task in Azure Pipelines. This avoids re-downloading packages on each run. Option A (self-hosted agent) is not guaranteed to cache the packages folder across builds unless caching is explicitly configured. Option B (faster network) may help but doesn't eliminate the restore time. Option C (larger SKU) improves CPU/memory but does not cache packages. Therefore, option D is correct.
Variation 2. Your Azure Pipelines build takes 45 minutes. You want to reduce build time by caching dependencies. Which task should you add to the pipeline?
easy- A.PublishBuildArtifacts@1
- B.CopyFiles@2
- C.DownloadBuildArtifacts@0
- ✓ D.Cache@2
Why D: Cache@2 is the correct task because it allows you to cache dependencies (e.g., npm packages, Maven artifacts) between pipeline runs, significantly reducing build time by avoiding re-downloading unchanged dependencies. This task stores and restores a cache keyed by a hash of the dependency files, enabling incremental builds.
Variation 3. Your organization uses Azure Pipelines with Microsoft-hosted agents. The pipeline runs a .NET Core application build. You notice that the build takes longer than expected. Which THREE actions can you take to improve build performance? (Choose three.)
hard- A.Add more build steps to the pipeline.
- ✓ B.Enable caching for NuGet packages.
- C.Increase the number of parallel jobs in the pipeline.
- ✓ D.Use multi-stage build with parallel test execution.
- ✓ E.Use a self-hosted agent with pre-installed dependencies.
Why B: Enabling NuGet package caching reduces build time by avoiding repeated downloads of packages. Using a self-hosted agent with pre-installed dependencies eliminates the need to install and download tools on each run, further reducing overhead. Additionally, structuring the pipeline as a multi-stage build and running tests in parallel across multiple agents can significantly shorten overall pipeline duration by executing independent test suites concurrently. Together, these optimizations improve build performance.
Variation 4. You have a YAML pipeline that builds a .NET application. You want to cache the NuGet packages to speed up subsequent builds. Which task should you use?
medium- A.CopyFiles task to copy packages to a staging directory.
- B.NuGet restore task with 'cacheRestore' option.
- ✓ C.Cache task with a key based on the packages.lock.json hash.
- D.PublishBuildArtifacts task to upload packages.
Why C: The Cache task in Azure Pipelines allows you to cache NuGet packages by specifying a key derived from the hash of `packages.lock.json`. This ensures that the cache is invalidated only when the lock file changes, which accurately reflects changes in package dependencies. The cached `~/.nuget/packages` folder is then restored on subsequent runs, significantly reducing restore time.
Variation 5. A company uses Azure Pipelines to build a .NET Core application. The build takes 45 minutes due to dependency restoration. They want to reduce build time. What is the most effective strategy?
hard- ✓ A.Cache the NuGet packages and enable caching in the pipeline
- B.Use parallel jobs in the pipeline
- C.Use a self-hosted agent with more CPU
- D.Enable incremental builds
Why A: Caching NuGet packages in Azure Pipelines is the most effective strategy because dependency restoration is the primary bottleneck, often downloading hundreds of packages from nuget.org. By caching the ~/.nuget/packages folder, subsequent builds skip the network download entirely, reducing the 45-minute build time to minutes. This directly addresses the root cause—repetitive package restoration—without requiring additional infrastructure or parallelism.
Variation 6. Your company uses Azure DevOps for CI/CD. You have a build pipeline that compiles a C++ application and runs unit tests. The pipeline uses a Microsoft-hosted agent. The build takes approximately 45 minutes to complete. You want to reduce the build time. You notice that the pipeline downloads dependencies from a NuGet feed every time. You have a private NuGet feed in Azure Artifacts. The pipeline restores packages using 'nuget restore'. You want to cache the NuGet packages on the agent to avoid downloading them on every build. What should you do?
medium- A.Use a self-hosted agent with persistent storage.
- B.Use a hosted Azure Artifacts feed with upstream sources.
- C.Increase the agent's compute resources by selecting a higher SKU.
- ✓ D.Add a CacheBeta task before the restore step to cache the packages folder.
Why D: The CacheBeta task enables caching of the NuGet packages folder between pipeline runs, avoiding repeated downloads from the feed. This directly reduces build time. Option A is wrong because while self-hosted agents can have persistent storage, the question specifies using a Microsoft-hosted agent, and the CacheBeta task works even with Microsoft-hosted agents. Option B is wrong because using upstream sources in Azure Artifacts does not cache packages locally on the agent; it still requires downloading them each time. Option C is wrong because increasing compute resources does not affect the time spent downloading dependencies; caching addresses the root cause.
Variation 7. Your team uses Azure DevOps to build a .NET application. The build pipeline takes 45 minutes to complete. You want to reduce build times by caching dependencies. What should you configure in the pipeline?
medium- A.Configure a Build Retention Policy to keep only the latest build.
- ✓ B.Add a Cache task with a key based on the package-lock.json file hash.
- C.Use Pipeline Artifacts to store dependencies between builds.
- D.Enable Incremental builds in the pipeline settings.
Why B: None of the options are correct. For a .NET application, you should add a Cache task with a key based on packages.lock.json or the project files. Option B uses package-lock.json (npm), which will cause cache misses and fail to improve build times for .NET dependencies.
Variation 8. You have a YAML pipeline that uses a multi-stage build. You want to cache the restored NuGet packages across builds to improve performance. Which caching strategy should you use?
hard- ✓ A.Use the Cache@2 task with key: 'nuget | "$(Agent.OS)" | packages.lock.json', path: '$(System.DefaultWorkingDirectory)/packages'
- B.Use the NuGetCommand@2 task with the -Cache argument.
- C.Set the NUGET_PACKAGES environment variable to a custom path and rely on pipeline caching plugin.
- D.Use the DotNetCoreCLI@2 task with the --no-restore flag and manually copy packages.
Why A: The Cache@2 task is the recommended way to cache NuGet packages in Azure Pipelines. By using a cache key that includes the agent OS and the packages.lock.json file, the cache is invalidated only when the lock file changes, ensuring restored packages are reused across builds. The path points to the NuGet global packages folder, which is typically $(System.DefaultWorkingDirectory)/packages when NUGET_PACKAGES is set.
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-400 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-400 exam.