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.
param(
[parameter(Mandatory=$true)] [string]$hostname
)
$url = "http://$hostname";
Write-Host "Opening URL : $url";
try{
$r = [System.Net.WebRequest]::Create($url);
$r.Timeout = 120000;
$resp = $r.GetResponse();
$resp.Close();
}
catch
{
Write-Error $_
##teamcity[buildStatus status='FAILURE'
[System.Environment]::Exit(1)
}
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.
param(
[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!
param( [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 comment