Created
January 2, 2014 09:25
-
-
Save feanz/df7bfa29d205d304ac3e to your computer and use it in GitHub Desktop.
Sitecore Website deployment scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Deployments made easy. Calls webdeploy, to automate deployments. It also calls the sitecore deserialization methods (via a page in your project) to update content, and then publishes (optional) | |
Parameters: | |
-packageFile <required> Full path to package file | |
-targetServer <required> Webdeploy service url | |
-userName <optional> Username for remote server | |
-password <optional> Password for remore user | |
-parametersFile <required> Full path to environment settings file | |
-publishServerUrl <optional> Base url of CM instance - required if publish is enabled | |
-noPublish <optional> Supress call to publish content after deploy | |
-whatif <optional> Run webdeploy test - shows which files will be affected, publishing is also supressed | |
.DESCRIPTION | |
Simply deployments for sitecore. Deploys via web deploy to remote servers. Deployments depending on configuration can be administrator or non-administrator deploys. | |
Once package is deployed, the serialization methods to deserialize from files is run. Typically this will be $serverUrl/sitecore/admin/deserialize.aspx and also a call to publish the updated content. | |
.PARAMETER packageFile | |
The web deploy package file - created with msbuild with the package option setup. | |
.PARAMETER targetServer | |
The web deploy service url - if you are using admin deployment url is typically <host>:8172/msdeploy.axd | |
If using a non admin account name for deployment, you need to include the IIS name - <host>:8172/msdeploy.axd?site='Default Website' | |
.PARAMETER parametersFile | |
SetParameters.xml customised for your specific environment. See webdeploy/msbuild for details to create these file(s). | |
.PARAMETER userName | |
The user name for the remote deploy | |
.PARAMETER password | |
The password for the remote deploy user. | |
.PARAMETER publishServerUrl | |
This should be the base url to the home page of your CM instance - eg http(s)://test.think.eu/ | |
.PARAMETER noPublish | |
If publish is not required (eg need to deploy to multiple servers before publish) specify this. Eg deployment to CD servers (Web1&web2) may not need publish until you run this package against the CM instance | |
.PARAMETER whatif | |
Run webdeploy in it's test mode - check output for what WILL be deployed. If not supplied changes will be applied to destination server. | |
.EXAMPLE | |
.\deploy.ps1 -packageFile "c:\deploy\project.zip" -targetServer "https://server1:8172/msdeploy.axd?site='default website'" -userName nonAdminDeploy -password Pa$$w0rd -publishServerUrl "http://cms.server/" -whatif | |
Run to verify which files will be updated/added/removed on destination server, files are not actually modified. No publishing or deserializing will be done. | |
.EXAMPLE | |
.\deploy.ps1 -packageFile "c:\deploy\project.zip" -targetServer "https://server1:8172/msdeploy.axd?site='default website'" -userName nonAdminDeploy -password Pa$$w0rd -publishServerUrl "http://cms.server/" -noPublish | |
Update, add, remove files on destination server. No publishing or deserializing will be done. | |
.EXAMPLE | |
.\deploy.ps1 -packageFile "c:\deploy\project.zip" -targetServer "https://cms.server:8172/msdeploy.axd?site='default website'" -userName nonAdminDeploy -password Pa$$w0rd -publishServerUrl "http://cms.server/" | |
Update, add, remove files on destination server. Deserialization and publishing will be done | |
#> | |
param( | |
[Parameter(Position=1)] | |
[string] $packageFile, | |
[Parameter(Position=2)] | |
[string] $targetServer, | |
[Parameter(Position=3)] | |
[string] $parametersFile, | |
[Parameter(Position=4)] | |
[string] $userName, | |
[Parameter(Position=5)] | |
[string] $password, | |
[Parameter(Position=6)] | |
[string] $publishServerUrl, | |
[switch] $noPublish, | |
[switch] $whatif, | |
[switch] $help | |
) | |
# Functions | |
function VerboseMessage([string]$message) | |
{ | |
Write-verbose $message | |
} | |
function WebDeploy | |
{ | |
Write-host "Web deploy" | |
$msdeployPath = (Get-ItemProperty -path 'HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\*\' -name "InstallPath").InstallPath | |
if($msdeployPath -eq ""){ | |
Write-error "MSdeploy is not installed on this machine." | |
exit | |
} | |
VerboseMessage "msdeploy found at $msdeployPath" | |
$whatifparam = "" | |
if($whatif -eq $true) | |
{ | |
VerboseMessage "Adding -whatif" | |
$whatifparam = " -whatif" | |
} | |
$verbose = "" | |
if($VerbosePreference) | |
{ | |
VerboseMessage "Adding -verbose" | |
$verbose = "-verbose" | |
} | |
$msdeployCommand=$msdeployPath +"msdeploy.exe" | |
VerboseMessage "MSDEPLOY: $msdeployCommand" | |
$msdeployArgs = "-source:package='$packageFile' -dest:auto,wmsvc='$targetServer',userName='$userName',password='$password',authtype='basic',includeAcls='$false' -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -skip:skipaction='Delete',objectname='dirPath',absolutepath='Layouts' -skip:skipaction='Delete',objectname='dirPath',absolutepath='App_Data' -skip:skipaction='Delete',objectname='dirPath',absolutepath='Temp' -skip:skipaction='Delete',objectname='filePath',absolutepath='Temp' -skip:skipaction='Delete',objectname='dirPath',absolutepath='sitecore' -skip:skipaction='Delete',objectname='filePath',absolutepath='sitecore' -skip:skipaction='Delete',objectname='dirPath',absolutepath='sitecore modules' -skip:skipaction='Delete',objectname='dirPath',absolutepath='upload' -skip:skipaction='Delete',objectname='filePath',absolutepath='upload' -allowuntrusted -skip:skipaction='Delete',objectname='dirPath',absolutepath='sitecore_files' -setParamFile:$parametersFile $whatifParam $verbose" | |
VerboseMessage "Full command: $msdeployCommand" | |
VerboseMessage "Full arguments: $msdeployArgs" | |
write-host "---- Webdeploy begin -----" -foregroundcolor Green | |
write-host "" | |
$process = (Start-Process -wait -passthru -nonewwindow -FilePath $msdeployCommand $msdeployArgs) | |
write-host "" | |
VerboseMessage("Webdeploy exit code " + $process.ExitCode) | |
if($process.ExitCode -ne 0) | |
{ | |
write-error -Message "Web deploy did not complete successfully. Please review and rectify the problem." | |
exit | |
} | |
write-host "---- Webdeploy done -----" -foregroundcolor Green | |
} | |
function Deserialize { | |
if(($whatif -eq $true) -or ($noPublish -eq $true)) | |
{ | |
write-host "Skipping deseralize and publish due to whatif/noPublish detected" -foregroundcolor:yellow | |
exit | |
} | |
Write-host "Deserialis(z)e All." | |
$deserialise = "$publishServerUrl/deployment/DeserializeAll" | |
VerboseMessage $deserialise | |
Get-WebPage $deserialise | |
Write-host "Publishing" | |
$publish = "$publishServerUrl/deployment/Publish" | |
VerboseMessage $publish | |
Get-WebPage $publish | |
write-host "All Done" | |
} | |
function CheckParams ($helpPath) { | |
$showHelp = $false | |
if (([string]::IsNullOrEmpty($packageFile)) -or ([string]::IsNullOrEmpty($targetServer))) | |
{ | |
$showHelp = $true | |
} | |
#if not set to publish publishServerUrl is optional. | |
if(($noPublish -eq $true) -or ($whatif -eq $true) ) | |
{ | |
#nothing to display | |
} | |
elseif([string]::IsNullOrEmpty($publishServerUrl)) | |
{ | |
$showHelp = $true; | |
} | |
if($showHelp -eq $true) | |
{ | |
write-host "" | |
write-host "Incorrect usage/missing parameters. See below for further details." -foregroundcolor Red | |
write-host "" | |
get-help $helpPath -examples | |
exit | |
} | |
} | |
# END Functions | |
if($help) | |
{ | |
get-help $myInvocation.MyCommand.Path | |
exit | |
} | |
CheckParams $myInvocation.MyCommand.Path | |
# Framework initialization | |
$scriptRoot = Split-Path (Resolve-Path $myInvocation.MyCommand.Path) | |
$env:PSModulePath = $env:PSModulePath + ";$scriptRoot\Framework" | |
# Import the webutils powercore cmdlet | |
Import-Module WebUtils\WebUtils | |
WebDeploy | |
Deserialize |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Quick deploy to various environments. | |
.DESCRIPTION | |
Calls deploy.ps1 with relevant arguments for repeatable deployments. | |
.PARAMETER deployTo | |
Specify the environment to deploy to. Currently supports "Dev-CMS" and "Dev-CD" | |
.PARAMETER TestDeploy | |
Test the deploy will work, and which files may be affected | |
.PARAMETER noPublish | |
Do a deploy, but will skip the final step of deserializing and publishing | |
#> | |
param( | |
[Parameter(Position=1)] | |
[string] $deployTo = "UKB_Dev_CMS", | |
[switch] $TestDeploy, | |
[switch] $noPublish, | |
[Parameter(Mandatory=$true)][string]$username, | |
[Parameter(Mandatory=$true)][string]$password | |
) | |
# Web Deploy Username and Password | |
#$username = "Deploy" | |
#$password = "Udish.Quaft7" | |
$devdatabase = "{databaseIP/name}" | |
$devdatabaseUsername = "{databaseusername}" | |
$devdatabasePassword = "{databasepassword}" | |
$siteID = "{EnvironmentSite}" | |
$targetHost = "" | |
$paramsFile = "" | |
if($deployTo -eq "CMS") | |
{ | |
$paramsFile = "{ParameterFile}.SetParameters.xml" | |
$targetHost = "10.1.0.211" | |
} | |
elseif($deployTo -eq "CDS") | |
{ | |
$paramsFile = "{ParameterFile}.SetParameters.xml" | |
$targetHost = "" | |
$noPublish = $True # It should be disabled via IIS permissions anyway | |
} | |
$path = split-path $MyInvocation.MyCommand.Path | |
write-host "Path: $path" | |
$deployParams = "-packageFile $path\Think.UKB.Portal.Web.zip -targetServer https://"+ $targetHost +":8172/msdeploy.axd?site=$siteID -parametersFile $path\$paramsFile -userName $username -password $password -publishServerUrl http://$targetHost -verbose" | |
if($TestDeploy -eq $true){ | |
$deployParams = "$deployParams -whatif" | |
} | |
if($noPublish -eq $true){ | |
$deployParams = "$deployParams -noPublish" | |
} | |
write-host $deployParams -foregroundcolor yellow | |
invoke-expression "$path\deploy.ps1 $deployParams" | |
write-host "Migrating DB" -foregroundcolor yellow | |
invoke-expression "$path\Migrations\migrate.ps1 -Server $devdatabase -Database UKB -Username $devdatabaseUsername -Password $devdatabasePassword -MigrationsDir ApplicationMigrations -Maximum" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment