Guest User

Untitled

a guest
Nov 8th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. # Parameters are expected in the following order:
  2. # 1. Path to ms deploy eg. "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
  3. # 2. Source server name eg. server1.domain.net
  4. # 3. Path to setParameters.xml which contains 'IIS Web Application Name' override [Comma delimitted]
  5. # 4. User name eg. domain\username
  6. # 5. Password eg. ****** (Caveat: not escaped)
  7. # 6. Destination server name(s) [Comma delimitted] eg. server2.domain.net,server3.domain.net
  8.  
  9. param (
  10. [parameter(Mandatory=$true)] [string]$msdeploy,
  11. [parameter(Mandatory=$true)] [string]$source,
  12. [parameter(Mandatory=$true)] [string]$config,
  13. [parameter(Mandatory=$true)] [string]$username,
  14. [parameter(Mandatory=$true)] [string]$password,
  15. [parameter(Mandatory=$true)] [string]$destination
  16. )
  17.  
  18. try
  19. {
  20. Write-Host "##teamcity[blockOpened name='Parameters']"
  21. Write-Host "msdeploy => '$msdeploy'"
  22. Write-Host "source => '$source'"
  23. Write-Host "config => '$config'"
  24. Write-Host "destination => '$destination'"
  25. Write-Host "##teamcity[blockClosed name='Parameters']"
  26.  
  27. $configs = $config.Split(",")
  28. foreach ($config in $configs)
  29. {
  30. $file = New-Object System.IO.FileInfo ($config)
  31.  
  32. if (!$file.Exists)
  33. {
  34. throw "'$config' not found (Working: '" + (Get-Location) + "')."
  35. }
  36.  
  37. [xml]$xml = Get-Content $file.FullName
  38. $app = $xml.selectSingleNode("//setParameter[@name='IIS Web Application Name']/@value").Value
  39.  
  40. if ([string]::IsNullOrEmpty($app))
  41. {
  42. Write-Host $("##teamcity[message text='{0} does not specify IIS Web Application Name']" -f $file)
  43. continue
  44. }
  45.  
  46. $destination.Split(",") | ForEach {
  47.  
  48. $server = $_
  49.  
  50. $name = $("Syncing: [{0}|] {1} => {2}" -f $app, $source, $server)
  51.  
  52. Write-Host $("##teamcity[blockOpened name='{0}']" -f $name)
  53. $command = $("`"{0}`" -verb:sync -source:iisApp='{1}',computername={2},userName='{3}',password='{4}',includeAcls='True',AuthType='NTLM' -dest:iisApp='{1}',computername='{5}',username='{3}',password='{4}',includeAcls='True',AuthType='NTLM'" -f $msdeploy, $app, $source, $username, $password, $server)
  54. cmd.exe /C "`"$command`""
  55.  
  56. if ($LastExitCode -ne 0) {
  57. [System.Environment]::Exit(1)
  58. }
  59. Write-Host $("##teamcity[blockClosed name='{0}']" -f $name)
  60. }
  61. }
  62. } Catch {
  63. Write-Host $("##teamcity[message text='{0}' status='ERROR']" -f $_.Exception.Message.Replace("]", "|]"))
  64. [System.Environment]::Exit(1)
  65. }
Add Comment
Please, Sign In to add comment