Tips & Tricks

Web application not updated after deployment with PowerShell DSC

At a customer I’m implementing automated deployment for one of their web applications. We’re using a PowerShell DSC script that is kicked off by Release Management (which is part of Microsoft Team Foundation Server). Part of that script is a “File” resource which takes care of actually deploying the new files.

While it for the first time, I discovered that updates were not deployed to the actual website, although changes were available from the source (the source directory where the files were being copied from). The part to ensure the up-to-date files were present in the web application location looked similar to this:

File WebContent
{
   Ensure          = 'Present'
   SourcePath      = 'C:\BitsToInstall\website'
   DestinationPath = 'C:\inetpub\wwwroot\website'
   Recurse         = $true
   Type            = 'Directory'
}

It looks like a default “File” resource, like you see in HelloWorld examples. I discovered that this is not enough to ensure new files or updated files are copied… There are extra lines you’ll need to ensure that this works:

File WebContent
{
   Ensure          = 'Present'
   SourcePath      = 'C:\BitsToInstall\website'
   DestinationPath = 'C:\inetpub\wwwroot\website'
   Recurse         = $true
   Type            = 'Directory'
   Checksum        = 'SHA-512'
   MatchSource     = $true
   Force           = $true
}

As you can see, there are some extra properties. These can be found at MSDN;

  • Checksum: by default, DSC verifies the action it should take based on filename. So if the file is already there, it will never copy again. Use SHA-1, SHA-256 or SHA-512 to ensure correct verification
  • Force: optional, will override certain errors that can occur during file copy
  • MatchSource: when set to true, it will also add files added after the first time the configuration is applied (otherwise it will only update existing files!)

So make sure you verify which options you need to deploy your application!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s