On the third day of Christmas, my true blog gave to me:

Three powershell scripts,
Two Keystone merge tips,
…and a placeholder rule in the content tree.

Let’s unwrap those scripts!

Open a URL

The below script can be used as a TeamCity build definition step to open a URL that you can pass in as a parameter to the script file. Helpful if you want to trigger some post-deployment logic, such as publishing, or just do a wake-up of the application instance.

 [parameter(Mandatory=$true)] [string]$hostname

$url = "http://$hostname";
Write-Host "Opening URL : $url";

   $r = [System.Net.WebRequest]::Create($url); 
   $r.Timeout = 120000; 
   $resp = $r.GetResponse();
   Write-Error $_
   ##teamcity[buildStatus status='FAILURE'

Clean up Include Files

The following script can be used to get rid of some Sitecore patch include files that were previously deployed and need to be deleted.

 [parameter(Mandatory=$true)] [string]$webroot,
 [parameter(Mandatory=$true)] [string]$projectfolder

$path = $webroot + '\App_Config\Include\'
$projectfiles = $path + $projectfolder + '\*.*'

Write-Host "Removing $projectfiles";
if(Test-Path -Path $projectfiles){
   Remove-Item $projectfiles
   Write-Host ">> Items removed.";

Robocopy deploys

Sometimes you just want to robocopy a bunch of files!

 [parameter(Mandatory=$true)] [string]$deployDir,
 [parameter(Mandatory=$true)] [string]$packageDir,
 [parameter(Mandatory=$true)] [string]$invalidDirs,
 [parameter(Mandatory=$true)] [string]$invalidFileMask

$excludeDirs = $invalidDirs -split ",";
$excludeFiles = $invalidFileMask -split ",";

Write-Host "Deploying package from [$packageDir] to: [$deployDir].";
Write-Host " >> Excluding Directories: $excludeDirs";
Write-Host " >> Excluding Files: $excludeFiles";

robocopy $packageDir $deployDir /E /xd $excludeDirs /XF $excludeFiles;
exit ($LastExitCode -band 24)


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 )

Facebook photo

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

Connecting to %s