-
Notifications
You must be signed in to change notification settings - Fork 0
Example 3
TeamCity has a bundled PowerShell runner which can be used to execute the backups.
You just have to configure the runner properly and have access to the WDP.Backup
PowerShell module.
The following example will show you how to accomplish that.
You can either:
- use NuGet
Install-Package WDP.Backup
. (preferred way)
- note: this installs a solution-level NuGet package and the PS file will be placed in the
packages
folder.
- or manually download the PS file to a desired location and add it to source control.
If you decide to use NuGet , which I'd recommend btw, the package is installed as a solution-level package.
That means that the package won't be installed into any project but instead added to 'global/solution' packages.config
file. NuGet package restore will however not work OOB with solution-level packages.
So to get the PS module to work within TeamCity you'd have to use either one of these methods:
- use package restore on the TeamCity server.
- add the
WDP.Backup.[version]
package (folder) to version control (not recommended).
Add a new build step and select the PowerShell runner.
- I'm assuming that the PS module is downloaded via NuGet.
-
I'd recommend leaving the working directory empty (checkout directory is default).
-
Select Source Code mode
OK, now it's time to execute the backup.
- Import the module:
Import-Module .\packages\WDP.Backup.%WDP.Backup.Version%\wdp.backup.psm1
You might notice that I've used a parameter for the package version (%WDP.Backup.Version%
). I'll explain why in a moment.
- Select which IIS applications/sites to backup via .publishsettings files:
Set-Properties @{ SourcePublishSettingsFiles = @("%cfg.ServersToBackup%")}
- note: the paths to the files are stored in a configuration parameter (
%cfg.ServersToBackup%
), like so:
- note: not required but makes it easier to maintain
- Execute the backup via
Invoke-Backup
The backup (.zip) is automatically added to the build artifacts.
Instead of hard-coding the version into the path to the script, like so:
You can instead extract the package version into a configuration parameter that can be changed and overridden.
The benefit being that you now also have the ability to "test/try" new NuGet versions by running a custom build and changing the parameter for that build only.
I've written an entire blog post on this that shows some more details if you're interested.