How to Build and Deploy Only Changed Files in Azure DevOps
Question details
The user needs to configure an Azure DevOps pipeline to build and deploy only modified artifacts to save time and reduce unnecessary processing.

- Product
- Azure DevOps
- Device & OS
- not provided
- Scenario
- Optimizing a CI/CD pipeline for faster execution and deployment.
- Observed behavior
- The pipeline needs to implement incremental builds and correctly handle dependencies, renamed files, and deleted files during deployment.
Ensure you have active Azure DevOps project administrator permissions and a working baseline pipeline before modifying your build and deployment processes.
Implement Incremental Builds and Custom Deployment Scripts
Utilize your build tool's incremental build capabilities alongside a script or specific deployment task that compares and transfers only modified files to the target environment.
To successfully deploy only changed files, you must first ensure that your build process only compiles modified source code. Afterward, a deployment tool or custom script is required to compare the newly built artifacts against the currently deployed files.
In your Azure DevOps build pipeline, configure your build task (such as MSBuild) to support incremental builds. Ensure that the 'Clean' option in your repository settings is disabled so previous build outputs are retained.
Add a 'Publish Build Artifacts' task to your pipeline to save the output of the incremental build, making it available for the release pipeline.
In your release pipeline, use a specialized deployment task (like Azure App Service Deploy with 'Zip Deploy') or write a custom PowerShell/Bash script to compare file hashes or timestamps and copy only the updated files.
Update your deployment script to detect files that exist in the target deployment but are missing in the new build artifact, and safely remove them to maintain application consistency.

Streamline Project Documentation with WPS Office
While you manage complex CI/CD pipelines in Azure DevOps, you need reliable tools for writing technical documentation. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office for all your project management needs.

Frequently Asked Questions
Does Azure DevOps have a built-in task to deploy only changed files?
While Azure DevOps itself orchestrates the pipeline, specific tasks like 'Azure App Service Deploy' offer features like 'Zip Deploy' which can update only changed files. For custom environments or VMs, you will likely need to implement your own script.
Why is my MSBuild recompiling all files instead of just changed ones?
This usually happens if the Azure DevOps agent is set to clean the workspace before each build. Ensure that 'Clean' is set to 'false' under the 'Get sources' step in your pipeline.
How can I synchronize deleted files during a deployment?
You can use tools like Web Deploy (msdeploy) with the '-enableRule:DoNotDeleteRule' removed, or use Robocopy with the '/MIR' (mirror) flag in your custom scripts to ensure deleted source files are removed from the destination.




