forked from rschiefer/MSDeployAllTheThings
/
MSDeployPackageSync.ps1
120 lines (87 loc) · 3.96 KB
/
MSDeployPackageSync.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
[CmdletBinding(DefaultParameterSetName = 'None')]
param
(
[String] [Parameter(Mandatory = $true)]
$Package,
[String] [Parameter(Mandatory = $true)]
$DestinationProvider,
[String] [Parameter(Mandatory = $false)]
$DestinationComputer,
[String] [Parameter(Mandatory = $false)]
$AuthType,
[String] [Parameter(Mandatory = $false)]
$Username,
[String] [Parameter(Mandatory = $false)]
$Password,
[String] [Parameter(Mandatory = $false)]
$AdditionalArguments
)
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Internal"
import-module "Microsoft.TeamFoundation.DistributedTask.Task.Common"
function Get-SingleFile($files, $pattern)
{
if ($files -is [system.array])
{
throw (Get-LocalizedString -Key "Found more than one file to deploy with search pattern {0}. There can be only one." -ArgumentList $pattern)
}
else
{
if (!$files)
{
throw (Get-LocalizedString -Key "No files were found to deploy with search pattern {0}" -ArgumentList $pattern)
}
return $files
}
}
Write-Host "packageFile= Find-Files -SearchPattern $Package"
$packageFile = Find-Files -SearchPattern $Package
Write-Host "packageFile= $packageFile"
#Ensure that at most a single package (.zip) file is found
$packageFile = Get-SingleFile $packageFile $Package
# adding System.Web explicitly, since we use http utility
Add-Type -AssemblyName System.Web
Write-Verbose "Entering script MSDeployPackageSync.ps1"
Write-Host "Package= $Package"
Write-Host "DestinationProvider= $DestinationProvider"
Write-Host "DestinationComputer= $DestinationComputer"
Write-Host "Username= $Username"
Write-Host "AdditionalArguments= $AdditionalArguments"
$MSDeployKey = 'HKLM:\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\3'
if(!(Test-Path $MSDeployKey)) {
throw "Could not find MSDeploy. Use Web Platform Installer to install the 'Web Deployment Tool' and re-run this command"
}
$InstallPath = (Get-ItemProperty $MSDeployKey).InstallPath
if(!$InstallPath -or !(Test-Path $InstallPath)) {
throw "Could not find MSDeploy. Use Web Platform Installer to install the 'Web Deployment Tool' and re-run this command"
}
$msdeploy = Join-Path $InstallPath "msdeploy.exe"
if(!(Test-Path $MSDeploy)) {
throw "Could not find MSDeploy. Use Web Platform Installer to install the 'Web Deployment Tool' and re-run this command"
}
# $publishUrl ="https://$Name.scm.azurewebsites.net:443/msdeploy.axd?site-name=$Name"
# $webApp ="$Name\$App"
Write-Host "Deploying $($packageFile.FileName) package to $DestinationComputer"
$remoteArguments = "computerName='$DestinationComputer',userName='$UserName',password='$Password',authType='$AuthType',"
if (-not $DestinationComputer -or -not $AuthType) {
Write-Host "No destination or authType defined, performing local operation"
$remoteArguments = ""
}
[string[]] $arguments =
"-verb:sync",
"-source:package='$packageFile'",
"-dest:$DestinationProvider,$($remoteArguments)includeAcls='False'",
#"-setParam:name='IIS", "Web", "Application", ("Name',value='" + $webApp + "'"),
"-allowUntrusted"
$fullCommand = """$msdeploy"" $arguments $AdditionalArguments"
Write-Host $fullCommand
# invoke-expression $fullCommand
# $block = $ExecutionContext.InvokeCommand.NewScriptBlock($fullCommand)
# & $block
$result = cmd.exe /c "$fullCommand"
Write-Host $result
Write-Verbose "Leaving script MSDeployPackageSync.ps1"
# PS D:\Github\vso-agent-tasks\Tasks\MSDeployPackageSync> .\MSDeployPackageSync.ps1 -DestinationProvider 'auto' -Package 'C:\temp\rootSitePackage\rootsite.zip'
# -DestinationComputer 'https://testingvirtualapps.scm.azurewebsites.net:443/msdeploy.axd?site=TestingVirtualApps' -AuthType 'basic' -DoNotDelete 'FALSE' -Use
# rname '$TestingVirtualApps' -Password 'Rvs7kwDcuPxAfq2EKLoqRQgWhxBkcNlGrzLzfomQsvFF74Rdi3tohRMhRPrh' -AdditionalArguments "-setParamFile:C:\temp\rootSitePack
# age\RootSite.SetParameters.xml"
# Package= C:\temp\rootSitePackage\rootsite.zip