1+ param (
2+ [string ]$environmentName ,
3+ [string ]$adminUserName ,
4+ [string ]$adminPassword ,
5+ [string ]$winrmProtocol ,
6+ [string ]$testCertificate ,
7+ [string ]$resourceFilteringMethod ,
8+ [string ]$machineFilter ,
9+ [string ]$webDeployPackage ,
10+ [string ]$webDeployParamFile ,
11+ [string ]$overRideParams ,
12+ [string ]$createWebSite ,
13+ [string ]$webSiteName ,
14+ [string ]$webSitePhysicalPath ,
15+ [string ]$webSitePhysicalPathAuth ,
16+ [string ]$webSiteAuthUserName ,
17+ [string ]$webSiteAuthUserPassword ,
18+ [string ]$addBinding ,
19+ [string ]$assignDuplicateBinding ,
20+ [string ]$protocol ,
21+ [string ]$ipAddress ,
22+ [string ]$port ,
23+ [string ]$hostNameWithHttp ,
24+ [string ]$hostNameWithOutSNI ,
25+ [string ]$hostNameWithSNI ,
26+ [string ]$serverNameIndication ,
27+ [string ]$sslCertThumbPrint ,
28+ [string ]$createAppPool ,
29+ [string ]$appPoolName ,
30+ [string ]$dotNetVersion ,
31+ [string ]$pipeLineMode ,
32+ [string ]$appPoolIdentity ,
33+ [string ]$appPoolUsername ,
34+ [string ]$appPoolPassword ,
35+ [string ]$appCmdCommands ,
36+ [string ]$deployInParallel
37+ )
38+
39+ Write-Warning " The preview IIS Web App Deployment task has been deprecated and will be removed soon. An IIS Web App Deployment extension has been released in the Visual Studio Team Services marketplace at https://aka.ms/iisextn. Install the extension, and use its tasks in the Build/Release definitions, and delete the preview task from the definition."
40+ Write-Verbose " Entering script DeployIISWebApp.ps1" - Verbose
41+
42+ $hostName = [string ]::Empty
43+
44+ if ($protocol -eq " http" )
45+ {
46+ $hostName = $hostNameWithHttp
47+ }
48+ elseif ($serverNameIndication -eq " true" )
49+ {
50+ $hostName = $hostNameWithSNI
51+ }
52+ else
53+ {
54+ $hostName = $hostNameWithOutSNI
55+ }
56+
57+ Write-Verbose " environmentName = $environmentName " - Verbose
58+ Write-Verbose " adminUserName = $adminUserName " - Verbose
59+ Write-Verbose " winrm protocol to connect to machine = $winrmProtocol " - Verbose
60+ Write-Verbose " testCertificate = $testCertificate " - Verbose
61+ Write-Verbose " resourceFilteringMethod = $resourceFilteringMethod " - Verbose
62+ Write-Verbose " machineFilter = $machineFilter " - Verbose
63+ Write-Verbose " webDeployPackage = $webDeployPackage " - Verbose
64+ Write-Verbose " webDeployParamFile = $webDeployParamFile " - Verbose
65+ Write-Verbose " overRideParams = $overRideParams " - Verbose
66+ Write-Verbose " deployInParallel = $deployInParallel " - Verbose
67+
68+ Write-Verbose " createWebSite = $createWebSite " - Verbose
69+ Write-Verbose " webSiteName = $webSiteName " - Verbose
70+ Write-Verbose " webSitePhysicalPath = $webSitePhysicalPath " - Verbose
71+ Write-Verbose " webSitePhysicalPathAuth = $webSitePhysicalPathAuth " - Verbose
72+ Write-Verbose " webSiteAuthUserName = $webSiteAuthUserName " - Verbose
73+ Write-Verbose " addBinding = $addBinding " - Verbose
74+ Write-Verbose " assignDuplicateBinding = $assignDuplicateBinding " - Verbose
75+ Write-Verbose " protocol = $protocol " - Verbose
76+ Write-Verbose " ipAddress = $ipAddress " - Verbose
77+ Write-Verbose " port = $port " - Verbose
78+ Write-Verbose " hostName = $hostName " - Verbose
79+ Write-Verbose " serverNameIndication = $serverNameIndication " - Verbose
80+
81+ Write-Verbose " createAppPool = $createAppPool " - Verbose
82+ Write-Verbose " appPoolName = $appPoolName " - Verbose
83+ Write-Verbose " dotNetVersion = $dotNetVersion " - Verbose
84+ Write-Verbose " pipeLineMode = $pipeLineMode " - Verbose
85+ Write-Verbose " appPoolIdentity = $appPoolIdentity " - Verbose
86+ Write-Verbose " appPoolUsername = $appPoolUsername " - Verbose
87+
88+ Write-Verbose " appCmdCommands = $appCmdCommands " - Verbose
89+ Write-Verbose " deployInParallel = $deployInParallel " - Verbose
90+
91+ import-module " Microsoft.TeamFoundation.DistributedTask.Task.Internal"
92+ import-module " Microsoft.TeamFoundation.DistributedTask.Task.Common"
93+ import-module " Microsoft.TeamFoundation.DistributedTask.Task.DevTestLabs"
94+ Import-Module " Microsoft.TeamFoundation.DistributedTask.Task.Deployment.Internal"
95+ Import-Module " Microsoft.TeamFoundation.DistributedTask.Task.Deployment.RemoteDeployment"
96+
97+ $webDeployPackage = $webDeployPackage.Trim (' "' , ' ' )
98+ $webDeployParamFile = $webDeployParamFile.Trim (' "' , ' ' )
99+ $webSiteName = $webSiteName.Trim (' "' , ' ' )
100+ $webSitePhysicalPath = $webSitePhysicalPath.Trim (' "' , ' ' )
101+ $webSiteAuthUserName = $webSiteAuthUserName.Trim ()
102+
103+ $appPoolName = $appPoolName.Trim (' "' , ' ' )
104+ $appPoolUsername = $appPoolUsername.Trim ()
105+
106+ $appCmdCommands = $appCmdCommands.Replace (' "' , ' `"' )
107+
108+ if ($createWebSite -ieq " true" -and [string ]::IsNullOrWhiteSpace($webSiteName ))
109+ {
110+ throw " Website Name cannot be empty if you want to create or update the target website."
111+ }
112+
113+ if ($createAppPool -ieq " true" -and [string ]::IsNullOrWhiteSpace($appPoolName ))
114+ {
115+ throw " Application pool name cannot be empty if you want to create or update the target app pool."
116+ }
117+
118+
119+ if (! [string ]::IsNullOrWhiteSpace($webSiteName ))
120+ {
121+ if ([string ]::IsNullOrWhiteSpace($overRideParams ))
122+ {
123+ Write-Verbose " Adding override params to ensure deployment happens on $webSiteName " - Verbose
124+ $overRideParams = [string ]::Format(' name="IIS Web Application Name",value="{0}"' , $webSiteName )
125+ }
126+ elseif (! $overRideParams.Contains (" IIS Web Application Name" ))
127+ {
128+ $overRideParams = $overRideParams + [string ]::Format(' {0}name="IIS Web Application Name",value="{1}"' , [System.Environment ]::NewLine, $webSiteName )
129+ }
130+ }
131+ $overRideParams = $overRideParams.Replace (' "' , ' `"' )
132+ $msDeployScript = Get-Content ./ MsDeployOnTargetMachines.ps1 | Out-String
133+ $invokeMain = " Execute-Main -WebDeployPackage `" $webDeployPackage `" -WebDeployParamFile `" $webDeployParamFile `" -OverRideParams `" $overRideParams `" -WebSiteName `" $webSiteName `" -WebSitePhysicalPath `" $webSitePhysicalPath `" -WebSitePhysicalPathAuth `" $webSitePhysicalPathAuth `" -WebSiteAuthUserName `" $webSiteAuthUserName `" -WebSiteAuthUserPassword `" $webSiteAuthUserPassword `" -AddBinding $addBinding -AssignDuplicateBinding $assignDuplicateBinding -Protocol $protocol -IpAddress `" $ipAddress `" -Port $port -HostName `" $hostName `" -ServerNameIndication $serverNameIndication -SslCertThumbPrint `" $sslCertThumbPrint `" -AppPoolName `" $appPoolName `" -DotNetVersion `" $dotNetVersion `" -PipeLineMode $pipeLineMode -AppPoolIdentity $appPoolIdentity -AppPoolUsername `" $appPoolUsername `" -AppPoolPassword `" $appPoolPassword `" -AppCmdCommands `" $appCmdCommands `" -CreateWebSite $createWebSite -CreateAppPool $createAppPool "
134+
135+ Write-Verbose " Executing main funnction in MsDeployOnTargetMachines : $invokeMain "
136+ $msDeployOnTargetMachinesScript = [string ]::Format(" {0} {1} ( {2} )" , $msDeployScript , [Environment ]::NewLine, $invokeMain )
137+ Write-Output ( Get-LocalizedString - Key " Starting deployment of IIS Web Deploy Package : {0}" - ArgumentList $webDeployPackage )
138+
139+ $errorMessage = [string ]::Empty
140+
141+ if ($resourceFilteringMethod -eq " tags" )
142+ {
143+ $errorMessage = Invoke-RemoteDeployment - environmentName $environmentName - tags $machineFilter - scriptBlockContent $msDeployOnTargetMachinesScript - runPowershellInParallel $deployInParallel - adminUserName $adminUserName - adminPassword $adminPassword - protocol $winrmProtocol - testCertificate $testCertificate
144+ }
145+ else
146+ {
147+ $errorMessage = Invoke-RemoteDeployment - environmentName $environmentName - machineNames $machineFilter - scriptBlockContent $msDeployOnTargetMachinesScript - runPowershellInParallel $deployInParallel - adminUserName $adminUserName - adminPassword $adminPassword - protocol $winrmProtocol - testCertificate $testCertificate
148+ }
149+
150+ if (-not [string ]::IsNullOrEmpty($errorMessage ))
151+ {
152+ $readmelink = " https://aka.ms/iiswebappdeployreadme"
153+ $helpMessage = (Get-LocalizedString - Key " For more info please refer to {0}" - ArgumentList $readmelink )
154+ throw " $errorMessage $helpMessage "
155+ }
156+
157+ Write-Output ( Get-LocalizedString - Key " Successfully deployed IIS Web Deploy Package : {0}" - ArgumentList $webDeployPackage )
0 commit comments