Preserving Date Modified on Files Deployed via Build/Release Pipelines
App Dev Manager Patrick King shares some insight into preserving date modified on files deployed via Build/Release pipelines.
I was working on a DevOps scenario that involved automating the deployment of batch process files from one server to one or more other servers. To accomplish this, I created a build pipeline to collect certain files from the staging location and store them as Build Artifacts. I then created a release pipeline to ask for deployment approval and then deploy the build artifacts to servers in other environments.
The file deployment would be straightforward to do with the Copy Files task, but a complication arose: It was important to stakeholders that the original Date Modified from the source files be preserved on destination servers, as shown below.
The problem was that the date is not preserved when the build agent collects and stored file artifacts. That file metadata is simply not collected, and files on the destination server bore the date/time that they were deployed.
The solution was to preserve files in their original state by zipping them up in a zip archive and storing that archive file as the build artifact.
- I utilized the Archive Files task to bundle up the files on the source server as part of the build definition and store them in the Build artifacts folder.
- Then in the release definition, I used the Extract Files task to deploy the files to the destination server. In this way, the extracted files retained their original Date Modified.
A screenshot of the basic steps I used is shown below. I also included a delete files step to delete the old version of the files being deployed from the destination. There is an option in the Extract Files task to delete all files in the destination folder, but I needed to be more surgical than that.
Build Definition Example – Archive Files on Server
Release Definition Example – Delete Old Files and Extract/Deploy New Files