diff --git a/Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment-Legacy.ps1 b/Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment-Legacy.ps1 new file mode 100644 index 000000000000..fe286d01478d --- /dev/null +++ b/Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment-Legacy.ps1 @@ -0,0 +1,134 @@ +param +( + [String] [Parameter(Mandatory = $true)] + $ConnectedServiceName, + + [String] [Parameter(Mandatory = $true)] + $WebAppName, + + [String] [Parameter(Mandatory = $true)] + $DeployToSlotFlag, + + [String] [Parameter(Mandatory = $false)] + $ResourceGroupName, + + [String] [Parameter(Mandatory = $false)] + $SlotName, + + [String] [Parameter(Mandatory = $true)] + $Package, + + [String] [Parameter(Mandatory = $false)] + $SetParametersFile, + + [String] [Parameter(Mandatory = $false)] + $RemoveAdditionalFilesFlag, + + [String] [Parameter(Mandatory = $false)] + $ExcludeFilesFromAppDataFlag, + + [String] [Parameter(Mandatory = $false)] + $TakeAppOfflineFlag, + + [String] [Parameter(Mandatory = $false)] + $VirtualApplication, + + [String] [Parameter(Mandatory = $false)] + [String] $AdditionalArguments, + + [String] [Parameter(Mandatory = $false)] + [string]$WebAppUri +) + +Write-Verbose "Starting AzureRM WebApp Deployment Task" + +Write-Verbose "ConnectedServiceName = $ConnectedServiceName" +Write-Verbose "WebAppName = $WebAppName" +Write-Verbose "DeployToSlotFlag = $DeployToSlotFlag" +Write-Verbose "ResourceGroupName = $ResourceGroupName" +Write-Verbose "SlotName = $SlotName" +Write-Verbose "Package = $Package" +Write-Verbose "SetParametersFile = $SetParametersFile" +Write-Verbose "RemoveAdditionalFilesFlag = $RemoveAdditionalFilesFlag" +Write-Verbose "ExcludeFilesFromAppDataFlag = $ExcludeFilesFromAppDataFlag" +Write-Verbose "TakeAppOfflineFlag = $TakeAppOfflineFlag" +Write-Verbose "VirtualApplication = $VirtualApplication" +Write-Verbose "AdditionalArguments = $AdditionalArguments" +Write-Verbose "WebAppUri = $WebAppUri" + +$WebAppUri = $WebAppUri.Trim() +$Package = $Package.Trim('"').Trim() + +if( [string]::IsNullOrEmpty($Package) ){ + Throw (Get-LocalizedString -Key "Invalid webapp package path provided") +} + +$SetParametersFile = $SetParametersFile.Trim('"').Trim() + +# Import all the dlls and modules which have cmdlets we need +Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal" +Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Common" + +# Load all dependent files for execution +. $PSScriptRoot/LegacyUtils/AzureUtility-Legacy.ps1 +. $PSScriptRoot/LegacyUtils/Utility-Legacy.ps1 +. $PSScriptRoot/FindInstalledMSDeploy.ps1 + + # Importing required version of azure cmdlets according to azureps installed on machine + $azureUtility = Get-AzureUtility + + Write-Verbose "Loading $azureUtility" + . $PSScriptRoot\LegacyUtils\$azureUtility + +$ErrorActionPreference = 'Stop' + +#### MAIN EXECUTION OF AZURERM WEBAPP DEPLOYMENT TASK BEGINS HERE #### + +# Get msdeploy.exe path +$msDeployExePath = Get-MsDeployExePath + +# Ensure that at most a package (.zip) file is found +$packageFilePath = Get-SingleFilePath -file $Package + +# Since the SetParametersFile is optional, but it's a FilePath type, it will have the value System.DefaultWorkingDirectory when not specified +if( $SetParametersFile -eq $env:SYSTEM_DEFAULTWORKINGDIRECTORY -or $SetParametersFile -eq [String]::Concat($env:SYSTEM_DEFAULTWORKINGDIRECTORY, "\") -or [string]::IsNullOrEmpty($SetParametersFile)){ + $setParametersFilePath = "" +} else { + $setParametersFilePath = Get-SingleFilePath -file $SetParametersFile +} + +# Get destination azureRM webApp connection details +$azureRMWebAppConnectionDetails = Get-AzureRMWebAppConnectionDetails -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag ` + -resourceGroupName $ResourceGroupName -slotName $SlotName + +# webApp Name to be used in msdeploy command +$webAppNameForMSDeployCmd = Get-WebAppNameForMSDeployCmd -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag -slotName $SlotName + +# Construct arguments for msdeploy command +$msDeployCmdArgs = Get-MsDeployCmdArgs -packageFile $packageFilePath -webAppNameForMSDeployCmd $webAppNameForMSDeployCmd -azureRMWebAppConnectionDetails $azureRMWebAppConnectionDetails -removeAdditionalFilesFlag $RemoveAdditionalFilesFlag ` + -excludeFilesFromAppDataFlag $ExcludeFilesFromAppDataFlag -takeAppOfflineFlag $TakeAppOfflineFlag -virtualApplication $VirtualApplication -AdditionalArguments $AdditionalArguments ` + -setParametersFile $setParametersFilePath + +# Deploy azureRM webApp using msdeploy Command +Run-MsDeployCommand -msDeployExePath $msDeployExePath -msDeployCmdArgs $msDeployCmdArgs + +# Get azure webapp hosted url +$azureWebsitePublishURL = Get-AzureRMWebAppPublishUrl -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag ` + -resourceGroupName $ResourceGroupName -slotName $SlotName + +# Publish azure webApp url +Write-Host (Get-LocalizedString -Key "Webapp successfully published at Url : {0}" -ArgumentList $azureWebsitePublishURL) + +# Set ouput vairable with azureWebsitePublishUrl +if(-not [string]::IsNullOrEmpty($WebAppUri)) +{ + + if( [string]::IsNullOrEmpty($azureWebsitePublishURL)) + { + Throw (Get-LocalizedString -Key "Unable to retrieve webapp publish url for webapp : '{0}'." -ArgumentList $webAppName) + } + + Write-Host "##vso[task.setvariable variable=$WebAppUri;]$azureWebsitePublishURL" +} + +Write-Verbose "Completed AzureRM WebApp Deployment Task" \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment.ps1 b/Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment.ps1 index 043c9dd84ecf..f18db54f3fb9 100644 --- a/Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment.ps1 +++ b/Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment.ps1 @@ -1,134 +1,107 @@ -param -( - [String] [Parameter(Mandatory = $true)] - $ConnectedServiceName, +[CmdletBinding()] +param() - [String] [Parameter(Mandatory = $true)] - $WebAppName, +Trace-VstsEnteringInvocation $MyInvocation - [String] [Parameter(Mandatory = $true)] - $DeployToSlotFlag, +try{ - [String] [Parameter(Mandatory = $false)] - $ResourceGroupName, + # Get inputs. + $WebAppName = Get-VstsInput -Name WebAppName -Require + $DeployToSlotFlag = Get-VstsInput -Name DeployToSlotFlag -Require -AsBool + $ResourceGroupName = Get-VstsInput -Name ResourceGroupName + $SlotName = Get-VstsInput -Name SlotName + $Package = Get-VstsInput -Name Package -Require + $RemoveAdditionalFilesFlag = Get-VstsInput -Name RemoveAdditionalFilesFlag -AsBool + $ExcludeFilesFromAppDataFlag = Get-VstsInput -Name ExcludeFilesFromAppDataFlag -AsBool + $TakeAppOfflineFlag = Get-VstsInput -Name TakeAppOfflineFlag -AsBool + $VirtualApplication = Get-VstsInput -Name VirtualApplication + $AdditionalArguments = Get-VstsInput -Name AdditionalArguments + $WebAppUri = Get-VstsInput -Name WebAppUri + $SetParametersFile = Get-VstsInput -Name SetParametersFile - [String] [Parameter(Mandatory = $false)] - $SlotName, + # Initialize Azure. - [String] [Parameter(Mandatory = $true)] - $Package, - - [String] [Parameter(Mandatory = $false)] - $SetParametersFile, + Import-Module $PSScriptRoot\ps_modules\VstsAzureHelpers_ + Initialize-Azure - [String] [Parameter(Mandatory = $false)] - $RemoveAdditionalFilesFlag, + # Import the loc strings. + Import-VstsLocStrings -LiteralPath $PSScriptRoot/Task.json - [String] [Parameter(Mandatory = $false)] - $ExcludeFilesFromAppDataFlag, + $WebAppUri = $WebAppUri.Trim() + $Package = "$Package".Trim('"').Trim() - [String] [Parameter(Mandatory = $false)] - $TakeAppOfflineFlag, - - [String] [Parameter(Mandatory = $false)] - $VirtualApplication, + if( [string]::IsNullOrEmpty($Package) ){ + Throw (Get-VstsLocString -Key "Invalidwebapppackagepathprovided") + } - [String] [Parameter(Mandatory = $false)] - [String] $AdditionalArguments, + $SetParametersFile = "$SetParametersFile".Trim('"').Trim() - [String] [Parameter(Mandatory = $false)] - [string]$WebAppUri -) -Write-Verbose "Starting AzureRM WebApp Deployment Task" + # Load all dependent files for execution + . $PSScriptRoot/AzureUtility.ps1 + . $PSScriptRoot/Utility.ps1 + . $PSScriptRoot/FindInstalledMSDeploy.ps1 -Write-Verbose "ConnectedServiceName = $ConnectedServiceName" -Write-Verbose "WebAppName = $WebAppName" -Write-Verbose "DeployToSlotFlag = $DeployToSlotFlag" -Write-Verbose "ResourceGroupName = $ResourceGroupName" -Write-Verbose "SlotName = $SlotName" -Write-Verbose "Package = $Package" -Write-Verbose "SetParametersFile = $SetParametersFile" -Write-Verbose "RemoveAdditionalFilesFlag = $RemoveAdditionalFilesFlag" -Write-Verbose "ExcludeFilesFromAppDataFlag = $ExcludeFilesFromAppDataFlag" -Write-Verbose "TakeAppOfflineFlag = $TakeAppOfflineFlag" -Write-Verbose "VirtualApplication = $VirtualApplication" -Write-Verbose "AdditionalArguments = $AdditionalArguments" -Write-Verbose "WebAppUri = $WebAppUri" + # Importing required version of azure cmdlets according to azureps installed on machine + $azureUtility = Get-AzureUtility -$WebAppUri = $WebAppUri.Trim() -$Package = $Package.Trim('"').Trim() + Write-Verbose "Loading $azureUtility" + . $PSScriptRoot/$azureUtility -Force -if( [string]::IsNullOrEmpty($Package) ){ - Throw (Get-LocalizedString -Key "Invalid webapp package path provided") -} + #### MAIN EXECUTION OF AZURERM WEBAPP DEPLOYMENT TASK BEGINS HERE #### -$SetParametersFile = $SetParametersFile.Trim('"').Trim() + # Get msdeploy.exe path + $msDeployExePath = Get-MsDeployExePath -# Import all the dlls and modules which have cmdlets we need -Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Internal" -Import-Module "Microsoft.TeamFoundation.DistributedTask.Task.Common" + # Ensure that at most a package (.zip) file is found + $packageFilePath = Get-SingleFilePath -file $Package -# Load all dependent files for execution -Import-Module ./AzureUtility.ps1 -Force -Import-Module ./Utility.ps1 -Force -Import-Module ./FindInstalledMSDeploy.ps1 + # Since the SetParametersFile is optional, but it's a FilePath type, it will have the value System.DefaultWorkingDirectory when not specified + if( $SetParametersFile -eq $env:SYSTEM_DEFAULTWORKINGDIRECTORY -or $SetParametersFile -eq [String]::Concat($env:SYSTEM_DEFAULTWORKINGDIRECTORY, "\" ) -or [string]::IsNullOrEmpty($SetParametersFile) ){ + $setParametersFilePath = "" + } else { + $setParametersFilePath = Get-SingleFilePath -file $SetParametersFile + } - # Importing required version of azure cmdlets according to azureps installed on machine - $azureUtility = Get-AzureUtility + # Get destination azureRM webApp connection details + $azureRMWebAppConnectionDetails = Get-AzureRMWebAppConnectionDetails -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag ` + -resourceGroupName $ResourceGroupName -slotName $SlotName - Write-Verbose "Loading $azureUtility" - Import-Module ./$azureUtility -Force + # webApp Name to be used in msdeploy command + $webAppNameForMSDeployCmd = Get-WebAppNameForMSDeployCmd -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag -slotName $SlotName -$ErrorActionPreference = 'Stop' + # Construct arguments for msdeploy command + $msDeployCmdArgs = Get-MsDeployCmdArgs -packageFile $packageFilePath -webAppNameForMSDeployCmd $webAppNameForMSDeployCmd -azureRMWebAppConnectionDetails $azureRMWebAppConnectionDetails -removeAdditionalFilesFlag $RemoveAdditionalFilesFlag ` + -excludeFilesFromAppDataFlag $ExcludeFilesFromAppDataFlag -takeAppOfflineFlag $TakeAppOfflineFlag -virtualApplication $VirtualApplication -AdditionalArguments $AdditionalArguments ` + -setParametersFile $setParametersFilePath -#### MAIN EXECUTION OF AZURERM WEBAPP DEPLOYMENT TASK BEGINS HERE #### + # Deploy azureRM webApp using msdeploy Command + Run-MsDeployCommand -msDeployExePath $msDeployExePath -msDeployCmdArgs $msDeployCmdArgs -# Get msdeploy.exe path -$msDeployExePath = Get-MsDeployExePath + # Get azure webapp hosted url + $azureWebsitePublishURL = Get-AzureRMWebAppPublishUrl -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag ` + -resourceGroupName $ResourceGroupName -slotName $SlotName -# Ensure that at most a package (.zip) file is found -$packageFilePath = Get-SingleFilePath -file $Package - -# Since the SetParametersFile is optional, but it's a FilePath type, it will have the value System.DefaultWorkingDirectory when not specified -if( $SetParametersFile -eq $env:SYSTEM_DEFAULTWORKINGDIRECTORY -or $SetParametersFile -eq [String]::Concat($env:SYSTEM_DEFAULTWORKINGDIRECTORY, "\") -or [string]::IsNullOrEmpty($SetParametersFile)){ - $setParametersFilePath = "" -} else { - $setParametersFilePath = Get-SingleFilePath -file $SetParametersFile -} + # Publish azure webApp url + Write-Host (Get-VstsLocString -Key "WebappsuccessfullypublishedatUrl0" -ArgumentList $azureWebsitePublishURL) -# Get destination azureRM webApp connection details -$azureRMWebAppConnectionDetails = Get-AzureRMWebAppConnectionDetails -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag ` - -resourceGroupName $ResourceGroupName -slotName $SlotName - -# webApp Name to be used in msdeploy command -$webAppNameForMSDeployCmd = Get-WebAppNameForMSDeployCmd -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag -slotName $SlotName - -# Construct arguments for msdeploy command -$msDeployCmdArgs = Get-MsDeployCmdArgs -packageFile $packageFilePath -webAppNameForMSDeployCmd $webAppNameForMSDeployCmd -azureRMWebAppConnectionDetails $azureRMWebAppConnectionDetails -removeAdditionalFilesFlag $RemoveAdditionalFilesFlag ` - -excludeFilesFromAppDataFlag $ExcludeFilesFromAppDataFlag -takeAppOfflineFlag $TakeAppOfflineFlag -virtualApplication $VirtualApplication -AdditionalArguments $AdditionalArguments ` - -setParametersFile $setParametersFilePath + # Set ouput vairable with azureWebsitePublishUrl + if(-not [string]::IsNullOrEmpty($WebAppUri)) + { + + if( [string]::IsNullOrEmpty($azureWebsitePublishURL)) + { + Throw (Get-VstsLocString -Key "Unabletoretrievewebapppublishurlforwebapp0" -ArgumentList $webAppName) + } + + Set-VstsTaskVariable -Name $WebAppUri -Value $azureWebsitePublishURL + } -# Deploy azureRM webApp using msdeploy Command -Run-MsDeployCommand -msDeployExePath $msDeployExePath -msDeployCmdArgs $msDeployCmdArgs + Write-Verbose "Completed AzureRM WebApp Deployment Task" -# Get azure webapp hosted url -$azureWebsitePublishURL = Get-AzureRMWebAppPublishUrl -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag ` - -resourceGroupName $ResourceGroupName -slotName $SlotName +} finally { + Trace-VstsLeavingInvocation $MyInvocation +} -# Publish azure webApp url -Write-Host (Get-LocalizedString -Key "Webapp successfully published at Url : {0}" -ArgumentList $azureWebsitePublishURL) -# Set ouput vairable with azureWebsitePublishUrl -if(-not [string]::IsNullOrEmpty($WebAppUri)) -{ - - if( [string]::IsNullOrEmpty($azureWebsitePublishURL)) - { - Throw (Get-LocalizedString -Key "Unable to retrieve webapp publish url for webapp : '{0}'." -ArgumentList $webAppName) - } - - Write-Host "##vso[task.setvariable variable=$WebAppUri;]$azureWebsitePublishURL" -} -Write-Verbose "Completed AzureRM WebApp Deployment Task" diff --git a/Tasks/AzureRmWebAppDeployment/AzureUtility.ps1 b/Tasks/AzureRmWebAppDeployment/AzureUtility.ps1 index 2d8fc59ec813..12f42d5f377f 100644 --- a/Tasks/AzureRmWebAppDeployment/AzureUtility.ps1 +++ b/Tasks/AzureRmWebAppDeployment/AzureUtility.ps1 @@ -2,24 +2,24 @@ $ErrorActionPreference = 'Stop' function Get-AzureUtility { - $currentVersion = Get-AzureCmdletsVersion + $currentVersion = (Get-Module -Name AzureRM.profile).Version Write-Verbose "Installed Azure PowerShell version: $currentVersion" $minimumAzureVersion = New-Object System.Version(0, 9, 9) - $versionCompatible = Get-AzureVersionComparison -AzureVersion $currentVersion -CompareVersion $minimumAzureVersion - + $azureUtilityOldVersion = "AzureUtilityLTE9.8.ps1" $azureUtilityNewVersion = "AzureUtilityGTE1.0.ps1" - - if(!$versionCompatible) + + + if( !$currentVersion -and $currentVersion -gt $minimumAzureVersion ) { - $azureUtilityRequiredVersion = $azureUtilityOldVersion + $azureUtilityRequiredVersion = $azureUtilityNewVersion } else { - $azureUtilityRequiredVersion = $azureUtilityNewVersion + $azureUtilityRequiredVersion = $azureUtilityOldVersion } - + Write-Verbose "Required AzureUtility: $azureUtilityRequiredVersion" return $azureUtilityRequiredVersion } @@ -58,7 +58,7 @@ function Get-AzureRMWebAppConnectionDetailsWithSpecificSlot [String][Parameter(Mandatory=$true)] $resourceGroupName, [String][Parameter(Mandatory=$true)] $slotName) - Write-Host (Get-LocalizedString -Key "Getting connection details for azureRM WebApp:'{0}' under Slot:'{1}'." -ArgumentList $webAppName, $slotName) + Write-Host (Get-VstsLocString -Key "GettingconnectiondetailsforazureRMWebApp0underSlot1" -ArgumentList $webAppName, $slotName) $kuduHostName = $webAppName + "-" + $slotName + ".scm.azurewebsites.net" Write-Verbose "`t Using KuduHostName:'$kuduHostName' for azureRM WebApp:'$webAppName' under Slot:'$slotName'." @@ -69,7 +69,7 @@ function Get-AzureRMWebAppConnectionDetailsWithSpecificSlot # construct object to store webApp connection details $azureRMWebAppConnectionDetailsWithSpecificSlot = Construct-AzureWebAppConnectionObject -kuduHostName $kuduHostName -webAppProfileForMSDeploy $webAppProfileForMSDeploy - Write-Host (Get-LocalizedString -Key "Got connection details for azureRM WebApp:'{0}' under Slot:'{1}'." -ArgumentList $webAppName, $slotName) + Write-Host (Get-VstsLocString -Key "GotconnectiondetailsforazureRMWebApp0underSlot1" -ArgumentList $webAppName, $slotName) return $azureRMWebAppConnectionDetailsWithSpecificSlot } @@ -77,7 +77,7 @@ function Get-AzureRMWebAppConnectionDetailsWithProductionSlot { param([String][Parameter(Mandatory=$true)] $webAppName) - Write-Host (Get-LocalizedString -Key "Getting connection details for azureRM WebApp:'{0}' under Production Slot." -ArgumentList $webAppName) + Write-Host (Get-VstsLocString -Key "GettingconnectiondetailsforazureRMWebApp0underProductionSlot" -ArgumentList $webAppName) $kuduHostName = $webAppName + ".scm.azurewebsites.net" Write-Verbose "`t Using KuduHostName:'$kuduHostName' for azureRM WebApp:'$webAppName' under default Slot." @@ -86,7 +86,7 @@ function Get-AzureRMWebAppConnectionDetailsWithProductionSlot $azureRMWebAppDetails = Get-AzureRMWebAppDetails -webAppName $webAppName if( $azureRMWebAppDetails.Count -eq 0 ){ - Throw (Get-LocalizedString -Key "WebApp '{0}' does not exist." -ArgumentList $webAppName) + Throw (Get-VstsLocString -Key "WebApp0doesnotexist" -ArgumentList $webAppName) } # Get resourcegroup name under which azure webApp exists @@ -102,7 +102,7 @@ function Get-AzureRMWebAppConnectionDetailsWithProductionSlot # construct object to store webApp connection details $azureRMWebAppConnectionDetailsWithProductionSlot = Construct-AzureWebAppConnectionObject -kuduHostName $kuduHostName -webAppProfileForMSDeploy $webAppProfileForMSDeploy - Write-Host (Get-LocalizedString -Key "Got connection details for azureRM WebApp:'{0}' under Production Slot." -ArgumentList $webAppName) + Write-Host (Get-VstsLocString -Key "GotconnectiondetailsforazureRMWebApp0underProductionSlot" -ArgumentList $webAppName) return $azureRMWebAppConnectionDetailsWithProductionSlot } diff --git a/Tasks/AzureRmWebAppDeployment/AzureUtilityGTE1.0.ps1 b/Tasks/AzureRmWebAppDeployment/AzureUtilityGTE1.0.ps1 index 11e422372409..b3da08173dd8 100644 --- a/Tasks/AzureRmWebAppDeployment/AzureUtilityGTE1.0.ps1 +++ b/Tasks/AzureRmWebAppDeployment/AzureUtilityGTE1.0.ps1 @@ -10,7 +10,7 @@ function Get-AzureRMWebAppARM if( $azureWebApp.Count -eq 0 ) { - Throw (Get-LocalizedString -Key "Web App: '{0}' not found." -ArgumentList $Name) + Throw (Get-VstsLocString -Key "WebApp0notfound" -ArgumentList $Name) } return $azureWebApp @@ -39,7 +39,7 @@ function Get-AzureRMWebAppPublishUrlARM } if( $azureRMWebAppProfileDetails -eq $null ){ - Throw (Get-LocalizedString -Key "Unable to find webapp publish profile details for webapp {0}." -ArgumentList $webAppName) + Throw (Get-VstsLocString -Key "Unabletofindwebapppublishprofiledetailsforwebapp0" -ArgumentList $webAppName) } return $azureRMWebAppProfileDetails.destinationAppUrl diff --git a/Tasks/AzureRmWebAppDeployment/AzureUtilityLTE9.8.ps1 b/Tasks/AzureRmWebAppDeployment/AzureUtilityLTE9.8.ps1 index bae6ebbadfe2..33582f0d8b72 100644 --- a/Tasks/AzureRmWebAppDeployment/AzureUtilityLTE9.8.ps1 +++ b/Tasks/AzureRmWebAppDeployment/AzureUtilityLTE9.8.ps1 @@ -42,7 +42,7 @@ function Get-AzureRMWebAppPublishUrlARM $azureRMWebAppProfileDetails = $azureRMWebAppProfileDetails | Where-Object { $_.PublishMethod -eq 'MSDeploy'} if( $azureRMWebAppProfileDetails.Count -eq 0 -or $azureRMWebAppProfileDetails.DestinationAppUri -eq $null ){ - Throw (Get-LocalizedString -Key "Unable to find publish Url for WebApp '{0}'." -ArgumentList $webAppName) + Throw (Get-VstsLocString -Key "UnabletofindpublishUrlforWebApp0" -ArgumentList $webAppName) } return $azureRMWebAppProfileDetails.DestinationAppUri.OriginalString @@ -71,7 +71,7 @@ function Get-WebAppRGName { Write-Verbose "[Azure Call] Web App: $webAppName not found" - Throw (Get-LocalizedString -Key "Web App: '{0}' not found." -ArgumentList $webAppName) + Throw (Get-VstsLocString -Key "WebApp0notfound" -ArgumentList $webAppName) } } } diff --git a/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtility-Legacy.ps1 b/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtility-Legacy.ps1 new file mode 100644 index 000000000000..e6498f676fda --- /dev/null +++ b/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtility-Legacy.ps1 @@ -0,0 +1,126 @@ +$ErrorActionPreference = 'Stop' + +function Get-AzureUtility +{ + $currentVersion = Get-AzureCmdletsVersion + Write-Verbose "Installed Azure PowerShell version: $currentVersion" + + $minimumAzureVersion = New-Object System.Version(0, 9, 9) + $versionCompatible = Get-AzureVersionComparison -AzureVersion $currentVersion -CompareVersion $minimumAzureVersion + + $azureUtilityOldVersion = "AzureUtilityLTE9.8-Legacy.ps1" + $azureUtilityNewVersion = "AzureUtilityGTE1.0-Legacy.ps1" + + if(!$versionCompatible) + { + $azureUtilityRequiredVersion = $azureUtilityOldVersion + } + else + { + $azureUtilityRequiredVersion = $azureUtilityNewVersion + } + + Write-Verbose "Required AzureUtility: $azureUtilityRequiredVersion" + return $azureUtilityRequiredVersion +} + +function Get-AzureRMWebAppDetails +{ + param([String][Parameter(Mandatory=$true)] $webAppName) + + Write-Verbose "`t Getting azureRM WebApp:'$webAppName' details." + $azureRMWebAppDetails = Get-AzureRMWebAppARM -Name $webAppName + Write-Verbose "`t Got azureRM WebApp:'$webAppName' details." + + Write-Verbose ($azureRMWebAppDetails | Format-List | Out-String) + return $azureRMWebAppDetails +} + +function Get-AzureRMWebAppPublishUrl +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $deployToSlotFlag, + [String][Parameter(Mandatory=$false)] $resourceGroupName, + [String][Parameter(Mandatory=$false)] $slotName) + + Write-Verbose "`t Getting azureRM WebApp Url for web app :'$webAppName'." + $AzureRMWebAppPublishUrl = Get-AzureRMWebAppPublishUrlARM -webAppName $WebAppName -deployToSlotFlag $DeployToSlotFlag ` + -resourceGroupName $ResourceGroupName -slotName $SlotName + Write-Verbose "`t Got azureRM azureRM WebApp Url for web app :'$webAppName'." + + Write-Verbose ($AzureRMWebAppPublishUrl | Format-List | Out-String) + return $AzureRMWebAppPublishUrl +} + +function Get-AzureRMWebAppConnectionDetailsWithSpecificSlot +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $resourceGroupName, + [String][Parameter(Mandatory=$true)] $slotName) + + Write-Host (Get-LocalizedString -Key "Getting connection details for azureRM WebApp:'{0}' under Slot:'{1}'." -ArgumentList $webAppName, $slotName) + + $kuduHostName = $webAppName + "-" + $slotName + ".scm.azurewebsites.net" + Write-Verbose "`t Using KuduHostName:'$kuduHostName' for azureRM WebApp:'$webAppName' under Slot:'$slotName'." + + # Get webApp publish profile Object for MSDeploy + $webAppProfileForMSDeploy = Get-AzureRMWebAppProfileForMSDeployWithSpecificSlot -webAppName $webAppName -resourceGroupName $resourceGroupName -slotName $slotName + + # construct object to store webApp connection details + $azureRMWebAppConnectionDetailsWithSpecificSlot = Construct-AzureWebAppConnectionObject -kuduHostName $kuduHostName -webAppProfileForMSDeploy $webAppProfileForMSDeploy + + Write-Host (Get-LocalizedString -Key "Got connection details for azureRM WebApp:'{0}' under Slot:'{1}'." -ArgumentList $webAppName, $slotName) + return $azureRMWebAppConnectionDetailsWithSpecificSlot +} + +function Get-AzureRMWebAppConnectionDetailsWithProductionSlot +{ + param([String][Parameter(Mandatory=$true)] $webAppName) + + Write-Host (Get-LocalizedString -Key "Getting connection details for azureRM WebApp:'{0}' under Production Slot." -ArgumentList $webAppName) + + $kuduHostName = $webAppName + ".scm.azurewebsites.net" + Write-Verbose "`t Using KuduHostName:'$kuduHostName' for azureRM WebApp:'$webAppName' under default Slot." + + # Get azurerm webApp details + $azureRMWebAppDetails = Get-AzureRMWebAppDetails -webAppName $webAppName + + if( $azureRMWebAppDetails.Count -eq 0 ){ + Throw (Get-LocalizedString -Key "WebApp '{0}' does not exist." -ArgumentList $webAppName) + } + + # Get resourcegroup name under which azure webApp exists + $azureRMWebAppId = $azureRMWebAppDetails.Id + Write-Verbose "azureRMWebApp Id = $azureRMWebAppId" + + $resourceGroupName = $azureRMWebAppId.Split('/')[4] + Write-Verbose "`t ResourceGroup name is:'$resourceGroupName' for azureRM WebApp:'$webAppName'." + + # Get webApp publish profile Object for MSDeploy + $webAppProfileForMSDeploy = Get-AzureRMWebAppProfileForMSDeployWithProductionSlot -webAppName $webAppName -resourceGroupName $resourceGroupName + + # construct object to store webApp connection details + $azureRMWebAppConnectionDetailsWithProductionSlot = Construct-AzureWebAppConnectionObject -kuduHostName $kuduHostName -webAppProfileForMSDeploy $webAppProfileForMSDeploy + + Write-Host (Get-LocalizedString -Key "Got connection details for azureRM WebApp:'{0}' under Production Slot." -ArgumentList $webAppName) + return $azureRMWebAppConnectionDetailsWithProductionSlot +} + +function Get-AzureRMWebAppConnectionDetails +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $deployToSlotFlag, + [String][Parameter(Mandatory=$false)] $resourceGroupName, + [String][Parameter(Mandatory=$false)] $slotName) + + if($deployToSlotFlag -eq "true") + { + $azureRMWebAppConnectionDetails = Get-AzureRMWebAppConnectionDetailsWithSpecificSlot -webAppName $webAppName -resourceGroupName $ResourceGroupName -slotName $SlotName + } + else + { + $azureRMWebAppConnectionDetails = Get-AzureRMWebAppConnectionDetailsWithProductionSlot -webAppName $webAppName + } + + return $azureRMWebAppConnectionDetails +} diff --git a/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtilityGTE1.0-Legacy.ps1 b/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtilityGTE1.0-Legacy.ps1 new file mode 100644 index 000000000000..93becd10d250 --- /dev/null +++ b/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtilityGTE1.0-Legacy.ps1 @@ -0,0 +1,177 @@ +# This file implements IAzureUtility for Azure PowerShell version >= 1.0.0 + +# returns azure webapp +function Get-AzureRMWebAppARM +{ + param([String] [Parameter(Mandatory = $true)] $Name) + + Write-Verbose "[Azure Call] Getting azure webapp details for webapp with name : $Name " + $azureWebApp = Get-AzureRMWebApp -Name $Name + + if( $azureWebApp.Count -eq 0 ) + { + Throw (Get-LocalizedString -Key "Web App: '{0}' not found." -ArgumentList $Name) + } + + return $azureWebApp + +} + +function Get-AzureRMWebAppPublishUrlARM +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $deployToSlotFlag, + [String][Parameter(Mandatory=$false)] $resourceGroupName, + [String][Parameter(Mandatory=$false)] $slotName) + + if( $deployToSlotFlag -eq $false ) + { + $resourceGroupName = Get-WebAppRGName -webAppName $webAppName + Write-Verbose "Getting azure webapp info for webapp with name : $Name " + $azureRMWebAppProfileDetails = Get-AzureRMWebAppProfileForMSDeployWithProductionSlot -webAppName $webAppName -resourceGroupName $resourceGroupName + Write-Verbose "Got azure webapp info for webapp with name : $Name " + } + else + { + Write-Verbose "Getting azure webapp slot info for webapp with name : $Name , slot : $slotName and resource group : $resourceGroupName" + $azureRMWebAppProfileDetails = Get-AzureRMWebAppProfileForMSDeployWithSpecificSlot -webAppName $webAppName -slotName $slotName -resourceGroupName $resourceGroupName + Write-Verbose "Got azure webapp slot info for webapp with name : $Name , slot : $slotName and resource group : $resourceGroupName" + } + + if( $azureRMWebAppProfileDetails -eq $null ){ + Throw (Get-LocalizedString -Key "Unable to find webapp publish profile details for webapp {0}." -ArgumentList $webAppName) + } + + return $azureRMWebAppProfileDetails.destinationAppUrl + +} + +function Get-WebAppRGName +{ + param([String] [Parameter(Mandatory = $true)] $webAppName) + + $ARMSqlServerResourceType = "Microsoft.Web/sites" + + try + { + Write-Verbose "[Azure Call] Getting resource details for webapp resource: $webAppName with resource type: $ARMSqlServerResourceType" + $azureWebAppResourceDetails = (Get-AzureRmResource -ErrorAction Stop) | Where-Object { $_.ResourceType -eq $ARMSqlServerResourceType -and $_.ResourceName -eq $webAppName} + Write-Verbose "[Azure Call] Retrieved resource details successfully for webapp resource: $webAppName with resource type: $ARMSqlServerResourceType" + + $azureResourceGroupName = $azureWebAppResourceDetails.ResourceGroupName + return $azureWebAppResourceDetails.ResourceGroupName + } + finally + { + if ([string]::IsNullOrEmpty($azureResourceGroupName)) + { + Write-Verbose "[Azure Call] Web App: $webAppName not found" + + Throw (Get-LocalizedString -Key "Web App: '{0}' not found." -ArgumentList $webAppName) + } + } +} + +# return azure webapp publish profile +function Get-AzureRMWebAppPublishingProfileARM +{ + param([String] [Parameter(Mandatory = $true)] $Name, + [String] [Parameter(Mandatory = $true)] $ResourceGroupName, + [String] [Parameter(Mandatory = $true)] $pubXmlFile) + + Write-Verbose "[Azure Call] Getting webapp publish profile for azureRM webapp : $Name " + $publishProfileContent = Get-AzureRMWebAppPublishingProfile -Name $Name -ResourceGroupName $resourceGroupName -OutputFile $pubXmlFile + return $publishProfileContent + +} + + +# return azure webapp slot publish profile +function Get-AzureRMWebAppSlotPublishingProfileARM +{ + param([String] [Parameter(Mandatory = $true)] $Name, + [String] [Parameter(Mandatory = $true)] $ResourceGroupName, + [String] [Parameter(Mandatory = $true)] $slotName, + [String] [Parameter(Mandatory = $true)] $pubXmlFile) + + Write-Verbose "[Azure Call] Getting publish profile file for azureRM WebApp:'$Name' for Slot:'$slotName'" + $publishProfileContent = Get-AzureRMWebAppSlotPublishingProfile -Name $Name -ResourceGroupName $resourceGroupName -Slot $slotName -OutputFile $pubXmlFile + return $publishProfileContent + +} + + + +function Construct-AzureWebAppConnectionObject +{ + param([String][Parameter(Mandatory=$true)] $kuduHostName, + [Object][Parameter(Mandatory=$true)] $webAppProfileForMSDeploy) + + # Get userName and userPassword to access kuduServer + $userName = $webAppProfileForMSDeploy.userName + $userPassword = $webAppProfileForMSDeploy.userPWD + Write-Verbose "`t Username is:'$userName' to access KuduHostName:'$kuduHostName'." + + $azureRMWebAppConnectionDetails = @{} + $azureRMWebAppConnectionDetails.KuduHostName = $kuduHostName + $azureRMWebAppConnectionDetails.UserName = $userName + $azureRMWebAppConnectionDetails.UserPassword = $userPassword + + return $azureRMWebAppConnectionDetails +} + +function Get-ProfileForMSDeployPublishMethod +{ + param([String][Parameter(Mandatory=$true)] $publishProfileContent) + + # Converting publish profile content into object + $publishProfileXML = [xml] $publishProfileContent + $publishProfileObject = $publishProfileXML.publishData.publishProfile + + # Getting profile for publish method 'MSDeploy' + $webAppProfileForMSDeploy = $publishProfileObject | Where-Object {$_.publishMethod -eq 'MSDeploy'} + + return $webAppProfileForMSDeploy +} + + +function Get-AzureRMWebAppProfileForMSDeployWithProductionSlot +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $resourceGroupName) + + $currentDir = (Get-Item -Path ".\").FullName + $tmpFileName = [guid]::NewGuid().ToString() + ".pubxml" + $pubXmlFile = Join-Path $currentDir $tmpFileName + + Write-Verbose "`t [Azure Call]Getting publish profile file for azureRM WebApp:'$webAppName' under Production Slot at location: '$pubXmlFile'." + $publishProfileContent = Get-AzureRMWebAppPublishingProfile -Name $webAppName -ResourceGroupName $resourceGroupName -OutputFile $pubXmlFile + Write-Verbose "`t [Azure Call]Got publish profile file for azureRM WebApp:'$webAppName' under Production Slot at location: '$pubXmlFile'." + + Remove-Item -Path $pubXmlFile -Force + Write-Verbose "`t Deleted publish profile file at location: '$pubXmlFile'" + + $webAppProfileForMSDeploy = Get-ProfileForMSDeployPublishMethod -publishProfileContent $publishProfileContent + return $webAppProfileForMSDeploy +} + +function Get-AzureRMWebAppProfileForMSDeployWithSpecificSlot +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $resourceGroupName, + [String][Parameter(Mandatory=$true)] $slotName) + + $currentDir = (Get-Item -Path ".\").FullName + $tmpFileName = [guid]::NewGuid().ToString() + ".pubxml" + $pubXmlFile = Join-Path $currentDir $tmpFileName + + Write-Verbose "`t [Azure Call]Getting publish profile file for azureRM WebApp:'$webAppName' under Slot:'$slotName' at location: '$pubXmlFile'." + $publishProfileContent = Get-AzureRMWebAppSlotPublishingProfile -Name $webAppName -ResourceGroupName $resourceGroupName -Slot $slotName -OutputFile $pubXmlFile + Write-Verbose "`t [Azure Call]Got publish profile file for azureRM WebApp:'$webAppName' under Slot:'$slotName' at location: '$pubXmlFile'." + + Remove-Item -Path $pubXmlFile -Force + Write-Verbose "`t Deleted publish profile file at location: '$pubXmlFile'" + + $webAppProfileForMSDeploy = Get-ProfileForMSDeployPublishMethod -publishProfileContent $publishProfileContent + return $webAppProfileForMSDeploy +} \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtilityLTE9.8-Legacy.ps1 b/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtilityLTE9.8-Legacy.ps1 new file mode 100644 index 000000000000..bae6ebbadfe2 --- /dev/null +++ b/Tasks/AzureRmWebAppDeployment/LegacyUtils/AzureUtilityLTE9.8-Legacy.ps1 @@ -0,0 +1,129 @@ +# This file implements IAzureUtility for Azure PowerShell version <= 0.9.8 + +# returns azure webapp +function Get-AzureRMWebAppARM +{ + param([String] [Parameter(Mandatory = $true)] $Name) + + Switch-AzureMode AzureResourceManager + + $resourceGroupName = Get-WebAppRGName -webAppName $Name + + Write-Verbose "[Azure Call] Getting azure webapp details for webapp with name : $Name and resource group $resourceGroupName " + $azureWebApp = Get-AzureWebApp -Name $Name -ResourceGroupName $resourceGroupName + return $azureWebApp + +} + +function Get-AzureRMWebAppPublishUrlARM +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $deployToSlotFlag, + [String][Parameter(Mandatory=$false)] $resourceGroupName, + [String][Parameter(Mandatory=$false)] $slotName) + + Switch-AzureMode AzureResourceManager + + $resourceGroupName = Get-WebAppRGName -webAppName $webAppName + + if( $deployToSlotFlag -eq $false ) + { + Write-Verbose "[Azure Call] Getting azure webapp publish profile info for webapp with name : $Name and resource group : $resourceGroupName" + $azureRMWebAppProfileDetails = Get-AzureWebAppPublishingProfile -Name $webAppName -ResourceGroupName $resourceGroupName + Write-Verbose "[Azure Call] Getting azure webapp publish profile info for webapp with name : $Name and resource group : $resourceGroupName" + } + else + { + Write-Verbose "[Azure Call] Getting azure webapp slot publish profile info for webapp with name : $Name , slot : $slotName and resource group : $resourceGroupName" + $azureRMWebAppProfileDetails = Get-AzureWebAppPublishingProfile -Name $webAppName -SlotName $slotName -ResourceGroupName $resourceGroupName + Write-Verbose "[Azure Call] Getting azure webapp slot publish profile info for webapp with name : $Name , slot : $slotName and resource group : $resourceGroupName" + } + + $azureRMWebAppProfileDetails = $azureRMWebAppProfileDetails | Where-Object { $_.PublishMethod -eq 'MSDeploy'} + + if( $azureRMWebAppProfileDetails.Count -eq 0 -or $azureRMWebAppProfileDetails.DestinationAppUri -eq $null ){ + Throw (Get-LocalizedString -Key "Unable to find publish Url for WebApp '{0}'." -ArgumentList $webAppName) + } + + return $azureRMWebAppProfileDetails.DestinationAppUri.OriginalString + +} + +function Get-WebAppRGName +{ + param([String] [Parameter(Mandatory = $true)] $webAppName) + + $ARMSqlServerResourceType = "Microsoft.Web/sites" + Switch-AzureMode AzureResourceManager + + try + { + Write-Verbose "[Azure Call] Getting resource details for webapp resource: $webAppName with resource type: $ARMSqlServerResourceType" + $azureWebAppResourceDetails = (Get-AzureResource -ResourceName $webAppName -ErrorAction Stop) | Where-Object { $_.ResourceType -eq $ARMSqlServerResourceType } + Write-Verbose "[Azure Call] Retrieved resource details successfully for webapp resource: $webAppName with resource type: $ARMSqlServerResourceType" + + $azureResourceGroupName = $azureWebAppResourceDetails.ResourceGroupName + return $azureWebAppResourceDetails.ResourceGroupName + } + finally + { + if ([string]::IsNullOrEmpty($azureResourceGroupName)) + { + Write-Verbose "[Azure Call] Web App: $webAppName not found" + + Throw (Get-LocalizedString -Key "Web App: '{0}' not found." -ArgumentList $webAppName) + } + } +} + + +function Construct-AzureWebAppConnectionObject +{ + param([String][Parameter(Mandatory=$true)] $kuduHostName, + [Object][Parameter(Mandatory=$true)] $webAppProfileForMSDeploy) + + # Get userName and userPassword to access kuduServer + $userName = $webAppProfileForMSDeploy.userName + $userPassword = $webAppProfileForMSDeploy.UserPassword + Write-Verbose "`t Username is:'$userName' to access KuduHostName:'$kuduHostName'." + + $azureRMWebAppConnectionDetails = @{} + $azureRMWebAppConnectionDetails.KuduHostName = $kuduHostName + $azureRMWebAppConnectionDetails.UserName = $userName + $azureRMWebAppConnectionDetails.UserPassword = $userPassword + + return $azureRMWebAppConnectionDetails +} + +function Get-AzureRMWebAppProfileForMSDeployWithProductionSlot +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $resourceGroupName) + + Switch-AzureMode AzureResourceManager + + Write-Verbose "`t [Azure Call]Getting publish profile file for azureRM WebApp:'$webAppName' under Production Slot." + $webAppProfiles = Get-AzureWebAppPublishingProfile -Name $webAppName -ResourceGroupName $resourceGroupName + Write-Verbose "`t [Azure Call]Got publish profile file for azureRM WebApp:'$webAppName' under Production Slot." + + $webAppProfileForMSDeploy = $webAppProfiles | Where-Object { $_.PublishMethod -eq 'MSDeploy'} + + return $webAppProfileForMSDeploy +} + +function Get-AzureRMWebAppProfileForMSDeployWithSpecificSlot +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $resourceGroupName, + [String][Parameter(Mandatory=$true)] $slotName) + + Switch-AzureMode AzureResourceManager + + Write-Verbose "`t [Azure Call]Getting publish profile file for azureRM WebApp:'$webAppName' under Slot:'$slotName'." + $webAppProfiles = Get-AzureWebAppPublishingProfile -Name $webAppName -ResourceGroupName $resourceGroupName -Slot $slotName + Write-Verbose "`t [Azure Call]Got publish profile file for azureRM WebApp:'$webAppName' under Slot:'$slotName'." + + $webAppProfileForMSDeploy = $webAppProfiles | Where-Object { $_.PublishMethod -eq 'MSDeploy'} + + return $webAppProfileForMSDeploy +} \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/LegacyUtils/Utility-Legacy.ps1 b/Tasks/AzureRmWebAppDeployment/LegacyUtils/Utility-Legacy.ps1 new file mode 100644 index 000000000000..a9c4fb0911c2 --- /dev/null +++ b/Tasks/AzureRmWebAppDeployment/LegacyUtils/Utility-Legacy.ps1 @@ -0,0 +1,188 @@ +$ErrorActionPreference = 'Stop' + +function Get-MsDeployExePath +{ + $MSDeployExePath = $null + try + { + $MSDeployExePath , $MSDeployVersion = Get-MSDeployOnTargetMachine + } + catch [System.Exception] + { + Write-Verbose ("MSDeploy is not installed in system." + $_.Exception.Message) + } + + if( $MSDeployExePath -ne $null -and $MSDeployVersion -lt 3 ){ + throw "Unsupported installed version : $MSDeployVersion found for MSDeploy,version should be alteast 3 or above" + } + + if( [string]::IsNullOrEmpty($MSDeployExePath) ) + { + + Write-Verbose (Get-LocalizedString -Key "Using local MSDeploy.exe") + $currentDir = (Get-Item -Path ".\").FullName + $msDeployExeDir = Join-Path $currentDir "MSDeploy3.6" + $MSDeployExePath = Join-Path $msDeployExeDir "msdeploy.exe" + + } + + Write-Host (Get-LocalizedString -Key "msdeploy.exe is located at '{0}'" -ArgumentList $MSDeployExePath) + + return $MSDeployExePath +} + +function Get-SingleFile +{ + param([String][Parameter(Mandatory=$true)] $files, + [String][Parameter(Mandatory=$true)] $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 + } +} + +function Get-SingleFilePath +{ + param([String][Parameter(Mandatory=$true)] $file) + + Write-Host (Get-LocalizedString -Key "filePath = Find-Files -SearchPattern {0}" -ArgumentList $file) + $filePath = Find-Files -SearchPattern $file + Write-Host (Get-LocalizedString -Key "filePath = {0}" -ArgumentList $filePath) + + $filePath = Get-SingleFile -files $filePath -pattern $file + return $filePath +} + +function Get-WebAppNameForMSDeployCmd +{ + param([String][Parameter(Mandatory=$true)] $webAppName, + [String][Parameter(Mandatory=$true)] $deployToSlotFlag, + [String][Parameter(Mandatory=$false)] $slotName) + + $webAppNameForMSDeployCmd = $webAppName + if($deployToSlotFlag -eq "true") + { + $webAppNameForMSDeployCmd += "(" + $SlotName + ")" + } + + Write-Verbose "WebApp Name to be used in msdeploy command is: '$webAppNameForMSDeployCmd'" + return $webAppNameForMSDeployCmd +} + + +function Get-MsDeployCmdArgs +{ + param([String][Parameter(Mandatory=$true)] $packageFile, + [String][Parameter(Mandatory=$true)] $webAppNameForMSDeployCmd, + [Object][Parameter(Mandatory=$true)] $azureRMWebAppConnectionDetails, + [String][Parameter(Mandatory=$true)] $removeAdditionalFilesFlag, + [String][Parameter(Mandatory=$true)] $excludeFilesFromAppDataFlag, + [String][Parameter(Mandatory=$true)] $takeAppOfflineFlag, + [String][Parameter(Mandatory=$false)] $virtualApplication, + [String][Parameter(Mandatory=$false)] $setParametersFile, + [String][Parameter(Mandatory=$false)] $AdditionalArguments) + + $msDeployCmdArgs = [String]::Empty + Write-Verbose "Constructing msdeploy command arguments to deploy to azureRM WebApp:'$webAppNameForMSDeployCmd' `nfrom source Wep App zip package:'$packageFile'." + + # msdeploy argument containing source and destination details to sync + $msDeployCmdArgs = [String]::Format('-verb:sync -source:package="{0}" -dest:auto,ComputerName="https://{1}/msdeploy.axd?site={2}",UserName="{3}",Password="{4}",AuthType="Basic"' ` + , $packageFile, $azureRMWebAppConnectionDetails.KuduHostName, $webAppNameForMSDeployCmd, $azureRMWebAppConnectionDetails.UserName, $azureRMWebAppConnectionDetails.UserPassword) + + # msdeploy argument to set destination IIS App Name for deploy + if($virtualApplication) + { + $msDeployCmdArgs += [String]::Format(' -setParam:name="IIS Web Application Name",value="{0}/{1}"', $webAppNameForMSDeployCmd, $virtualApplication) + } + else + { + $msDeployCmdArgs += [String]::Format(' -setParam:name="IIS Web Application Name",value="{0}"', $webAppNameForMSDeployCmd) + } + + # msdeploy argument to block deletion from happening + if($removeAdditionalFilesFlag -ne "true") + { + $msDeployCmdArgs += " -enableRule:DoNotDeleteRule" + } + + # msdeploy argument to take app offline + if($takeAppOfflineFlag -eq "true") + { + $msDeployCmdArgs += " -enableRule:AppOffline" + } + + # msdeploy argument to exclude files in App_Data folder + if($excludeFilesFromAppDataFlag -eq "true") + { + $msDeployCmdArgs += [String]::Format(' -skip:Directory="\\App_Data"') + } + + if( -not [String]::IsNullOrEmpty($setParametersFile)){ + $msDeployCmdArgs += [String]::Format(' -setParamFile:"{0}"', $setParametersFile) + } + + # msploy additional arguments + if( -not [String]::IsNullOrEmpty($AdditionalArguments)){ + $msDeployCmdArgs += ( " " + $AdditionalArguments) + } + + Write-Verbose "Constructed msdeploy command arguments to deploy to azureRM WebApp:'$webAppNameForMSDeployCmd' `nfrom source Wep App zip package:'$packageFile'." + return $msDeployCmdArgs +} + +function Run-Command +{ + param([String][Parameter(Mandatory=$true)] $command) + + try + { + if( $psversiontable.PSVersion.Major -le 4) + { + cmd.exe /c "`"$command`"" + } + else + { + cmd.exe /c "$command" + } + + } + catch [System.Exception] + { + throw $_.Exception.Message + } + +} + +function Get-MsDeployCmdForLogs +{ + param([String][Parameter(Mandatory=$true)] $msDeployCmd) + + $msDeployCmdSplitByComma = $msDeployCmd.Split(',') + $msDeployCmdHiddingSensitiveData = $msDeployCmdSplitByComma | ForEach-Object {if ($_.StartsWith("Password")) {$_.Replace($_, "Password=****")} else {$_}} + + $msDeployCmdForLogs = $msDeployCmdHiddingSensitiveData -join "," + return $msDeployCmdForLogs +} + +function Run-MsDeployCommand +{ + param([String][Parameter(Mandatory=$true)] $msDeployExePath, + [String][Parameter(Mandatory=$true)] $msDeployCmdArgs) + + $msDeployCmd = "`"$msDeployExePath`" $msDeployCmdArgs" + $msDeployCmdForLogs = Get-MsDeployCmdForLogs -msDeployCmd $msDeployCmd + + Write-Host (Get-LocalizedString -Key "Running msdeploy command: `n`t{0}" -ArgumentList $msDeployCmdForLogs) + Run-Command -command $msDeployCmd + Write-Host (Get-LocalizedString -Key "msdeploy command ran successfully.") +} \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson b/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson index 58932a5daacf..c905812ee297 100644 --- a/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson +++ b/Tasks/AzureRmWebAppDeployment/Strings/resources.resjson/en-US/resources.resjson @@ -29,5 +29,26 @@ "loc.input.label.AdditionalArguments": "Additional Arguments", "loc.input.help.AdditionalArguments": "Additional Web Deploy arguments that will be applied when deploying the Azure Web App like,-disableLink:AppPoolExtension -disableLink:ContentExtension.", "loc.input.label.WebAppUri": "Web App Hosted Url", - "loc.input.help.WebAppUri": "Provide a name for the variable for the webapp hosted url. The variable can be used as $(variableName) to refer to the hosted url of webapp in subsequent tasks like in the PowerShell on Target Machines task." + "loc.input.help.WebAppUri": "Provide a name for the variable for the webapp hosted url. The variable can be used as $(variableName) to refer to the hosted url of webapp in subsequent tasks like in the PowerShell on Target Machines task.", + "loc.messages.Invalidwebapppackagepathprovided": "Invalid webapp package path provided", + "loc.messages.WebappsuccessfullypublishedatUrl0": "Webapp successfully published at Url : {0}", + "loc.messages.Unabletoretrievewebapppublishurlforwebapp0": "Unable to retrieve webapp publish url for webapp : '{0}'.", + "loc.messages.GettingconnectiondetailsforazureRMWebApp0underSlot1": "Getting connection details for azureRM WebApp:'{0}' under Slot:'{1}'.", + "loc.messages.GotconnectiondetailsforazureRMWebApp0underSlot1": "Got connection details for azureRM WebApp:'{0}' under Slot:'{1}'.", + "loc.messages.GettingconnectiondetailsforazureRMWebApp0underProductionSlot": "Getting connection details for azureRM WebApp:'{0}' under Production Slot.", + "loc.messages.WebApp0doesnotexist": "WebApp '{0}' does not exist.", + "loc.messages.GotconnectiondetailsforazureRMWebApp0underProductionSlot": "Got connection details for azureRM WebApp:'{0}' under Production Slot.", + "loc.messages.WebApp0notfound": "Web App: '{0}' not found.", + "loc.messages.Unabletofindwebapppublishprofiledetailsforwebapp0": "Unable to find webapp publish profile details for webapp {0}.", + "loc.messages.UsinglocalMSDeployexe": "Using local MSDeploy.exe", + "loc.messages.msdeployexeislocatedat0": "msdeploy.exe is located at '{0}'", + "loc.messages.Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone": "Found more than one file to deploy with search pattern {0}. There can be only one.", + "loc.messages.Nofileswerefoundtodeploywithsearchpattern0": "No files were found to deploy with search pattern {0}.", + "loc.messages.packageFileFindFilesSearchPattern0": "packageFile = Find-Files -SearchPattern {0}", + "loc.messages.packageFile0": "packageFile = {0}", + "loc.messages.Runningmsdeploycommand0": "Running msdeploy command: `n`t{0}", + "loc.messages.msdeploycommandransuccessfully": "msdeploy command ran successfully.", + "loc.messages.filePathFindFilesSearchPattern0": "filePath = Find-Files -SearchPattern {0}", + "loc.messages.filePath0": "filePath = {0}", + "loc.messages.UnabletofindpublishUrlforWebApp0": "Unable to find publish Url for WebApp '{0}'." } \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/Utility.ps1 b/Tasks/AzureRmWebAppDeployment/Utility.ps1 index a9c4fb0911c2..62055c337c66 100644 --- a/Tasks/AzureRmWebAppDeployment/Utility.ps1 +++ b/Tasks/AzureRmWebAppDeployment/Utility.ps1 @@ -19,14 +19,14 @@ function Get-MsDeployExePath if( [string]::IsNullOrEmpty($MSDeployExePath) ) { - Write-Verbose (Get-LocalizedString -Key "Using local MSDeploy.exe") + Write-Verbose (Get-VstsLocString -Key "UsinglocalMSDeployexe") $currentDir = (Get-Item -Path ".\").FullName $msDeployExeDir = Join-Path $currentDir "MSDeploy3.6" $MSDeployExePath = Join-Path $msDeployExeDir "msdeploy.exe" } - Write-Host (Get-LocalizedString -Key "msdeploy.exe is located at '{0}'" -ArgumentList $MSDeployExePath) + Write-Host (Get-VstsLocString -Key msdeployexeislocatedat0 -ArgumentList $MSDeployExePath) return $MSDeployExePath } @@ -38,13 +38,13 @@ function Get-SingleFile 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) + throw (Get-VstsLocString -Key Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone -ArgumentList $pattern) } else { if (!$files) { - throw (Get-LocalizedString -Key "No files were found to deploy with search pattern {0}." -ArgumentList $pattern) + throw (Get-VstsLocString -Key Nofileswerefoundtodeploywithsearchpattern0 -ArgumentList $pattern) } return $files @@ -55,9 +55,9 @@ function Get-SingleFilePath { param([String][Parameter(Mandatory=$true)] $file) - Write-Host (Get-LocalizedString -Key "filePath = Find-Files -SearchPattern {0}" -ArgumentList $file) - $filePath = Find-Files -SearchPattern $file - Write-Host (Get-LocalizedString -Key "filePath = {0}" -ArgumentList $filePath) + Write-Host (Get-VstsLocString -Key filePathFindFilesSearchPattern0 -ArgumentList $file) + $filePath = Find-VstsFiles -LegacyPattern $file + Write-Host (Get-VstsLocString -Key filePath0 -ArgumentList $filePath) $filePath = Get-SingleFile -files $filePath -pattern $file return $filePath @@ -182,7 +182,7 @@ function Run-MsDeployCommand $msDeployCmd = "`"$msDeployExePath`" $msDeployCmdArgs" $msDeployCmdForLogs = Get-MsDeployCmdForLogs -msDeployCmd $msDeployCmd - Write-Host (Get-LocalizedString -Key "Running msdeploy command: `n`t{0}" -ArgumentList $msDeployCmdForLogs) + Write-Host (Get-VstsLocString -Key Runningmsdeploycommand0 -ArgumentList $msDeployCmdForLogs) Run-Command -command $msDeployCmd - Write-Host (Get-LocalizedString -Key "msdeploy command ran successfully.") + Write-Host (Get-VstsLocString -Key msdeploycommandransuccessfully ) } \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/task.json b/Tasks/AzureRmWebAppDeployment/task.json index f79a408c76ee..9e32182a3c9f 100644 --- a/Tasks/AzureRmWebAppDeployment/task.json +++ b/Tasks/AzureRmWebAppDeployment/task.json @@ -1,9 +1,9 @@ -{ +{ "id": "497D490F-EEA7-4F2B-AB94-48D9C1ACDCB1", "name": "AzureRMWebAppDeployment", "friendlyName": "AzureRM Web App Deployment ( Preview )", "description": "Deploy the web project to the AzureRM Web App using Web Deploy", - "helpMarkDown": "[More Information](http://aka.ms/azurermwebdeployreadme)", + "helpMarkDown": "[More Information](http://aka.ms/azurermwebdeployreadme)", "category": "Deploy", "visibility": [ "Build", @@ -13,10 +13,10 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 6 + "Patch": 7 }, "minimumAgentVersion": "1.99.0", - "groups": [ + "groups": [ { "name": "output", "displayName": "Output", @@ -122,7 +122,7 @@ "defaultValue": "", "required": false, "helpMarkDown": "Specify the name of the Virtual Application that has been configured in the Azure portal. The option is not required for deployments to the website root." - }, + }, { "name": "AdditionalArguments", "type": "string", @@ -131,7 +131,7 @@ "defaultValue": "", "helpMarkDown": "Additional Web Deploy arguments that will be applied when deploying the Azure Web App like,-disableLink:AppPoolExtension -disableLink:ContentExtension." }, - { + { "name": "WebAppUri", "type": "string", "label": "Web App Hosted Url", @@ -168,10 +168,36 @@ ], "instanceNameFormat": "Deploy AzureRM Web App: $(WebAppName)", "execution": { - "AzurePowerShell": { - "target": "$(currentDirectory)\\AzureRMWebAppDeployment.ps1", + "AzurePowerShell": { + "target": "$(currentDirectory)\\AzureRmWebAppDeployment-Legacy.ps1", "argumentFormat": "", "workingDirectory": "$(currentDirectory)" + }, + "PowerShell3": { + "target": "AzureRMWebAppDeployment.ps1" } + }, + "messages": { + "Invalidwebapppackagepathprovided": "Invalid webapp package path provided", + "WebappsuccessfullypublishedatUrl0": "Webapp successfully published at Url : {0}", + "Unabletoretrievewebapppublishurlforwebapp0": "Unable to retrieve webapp publish url for webapp : '{0}'.", + "GettingconnectiondetailsforazureRMWebApp0underSlot1": "Getting connection details for azureRM WebApp:'{0}' under Slot:'{1}'.", + "GotconnectiondetailsforazureRMWebApp0underSlot1": "Got connection details for azureRM WebApp:'{0}' under Slot:'{1}'.", + "GettingconnectiondetailsforazureRMWebApp0underProductionSlot": "Getting connection details for azureRM WebApp:'{0}' under Production Slot.", + "WebApp0doesnotexist": "WebApp '{0}' does not exist.", + "GotconnectiondetailsforazureRMWebApp0underProductionSlot": "Got connection details for azureRM WebApp:'{0}' under Production Slot.", + "WebApp0notfound": "Web App: '{0}' not found.", + "Unabletofindwebapppublishprofiledetailsforwebapp0": "Unable to find webapp publish profile details for webapp {0}.", + "UsinglocalMSDeployexe": "Using local MSDeploy.exe", + "msdeployexeislocatedat0": "msdeploy.exe is located at '{0}'", + "Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone": "Found more than one file to deploy with search pattern {0}. There can be only one.", + "Nofileswerefoundtodeploywithsearchpattern0": "No files were found to deploy with search pattern {0}.", + "packageFileFindFilesSearchPattern0": "packageFile = Find-Files -SearchPattern {0}", + "packageFile0": "packageFile = {0}", + "Runningmsdeploycommand0": "Running msdeploy command: `n`t{0}", + "msdeploycommandransuccessfully": "msdeploy command ran successfully.", + "filePathFindFilesSearchPattern0": "filePath = Find-Files -SearchPattern {0}", + "filePath0":"filePath = {0}", + "UnabletofindpublishUrlforWebApp0":"Unable to find publish Url for WebApp '{0}'." } } \ No newline at end of file diff --git a/Tasks/AzureRmWebAppDeployment/task.loc.json b/Tasks/AzureRmWebAppDeployment/task.loc.json index a2fda35c27b0..2cb56cab3735 100644 --- a/Tasks/AzureRmWebAppDeployment/task.loc.json +++ b/Tasks/AzureRmWebAppDeployment/task.loc.json @@ -13,7 +13,7 @@ "version": { "Major": 1, "Minor": 0, - "Patch": 6 + "Patch": 7 }, "minimumAgentVersion": "1.99.0", "groups": [ @@ -169,9 +169,35 @@ "instanceNameFormat": "ms-resource:loc.instanceNameFormat", "execution": { "AzurePowerShell": { - "target": "$(currentDirectory)\\AzureRMWebAppDeployment.ps1", + "target": "$(currentDirectory)\\AzureRmWebAppDeployment-Legacy.ps1", "argumentFormat": "", "workingDirectory": "$(currentDirectory)" + }, + "PowerShell3": { + "target": "AzureRMWebAppDeployment.ps1" } + }, + "messages": { + "Invalidwebapppackagepathprovided": "ms-resource:loc.messages.Invalidwebapppackagepathprovided", + "WebappsuccessfullypublishedatUrl0": "ms-resource:loc.messages.WebappsuccessfullypublishedatUrl0", + "Unabletoretrievewebapppublishurlforwebapp0": "ms-resource:loc.messages.Unabletoretrievewebapppublishurlforwebapp0", + "GettingconnectiondetailsforazureRMWebApp0underSlot1": "ms-resource:loc.messages.GettingconnectiondetailsforazureRMWebApp0underSlot1", + "GotconnectiondetailsforazureRMWebApp0underSlot1": "ms-resource:loc.messages.GotconnectiondetailsforazureRMWebApp0underSlot1", + "GettingconnectiondetailsforazureRMWebApp0underProductionSlot": "ms-resource:loc.messages.GettingconnectiondetailsforazureRMWebApp0underProductionSlot", + "WebApp0doesnotexist": "ms-resource:loc.messages.WebApp0doesnotexist", + "GotconnectiondetailsforazureRMWebApp0underProductionSlot": "ms-resource:loc.messages.GotconnectiondetailsforazureRMWebApp0underProductionSlot", + "WebApp0notfound": "ms-resource:loc.messages.WebApp0notfound", + "Unabletofindwebapppublishprofiledetailsforwebapp0": "ms-resource:loc.messages.Unabletofindwebapppublishprofiledetailsforwebapp0", + "UsinglocalMSDeployexe": "ms-resource:loc.messages.UsinglocalMSDeployexe", + "msdeployexeislocatedat0": "ms-resource:loc.messages.msdeployexeislocatedat0", + "Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone": "ms-resource:loc.messages.Foundmorethanonefiletodeploywithsearchpattern0Therecanbeonlyone", + "Nofileswerefoundtodeploywithsearchpattern0": "ms-resource:loc.messages.Nofileswerefoundtodeploywithsearchpattern0", + "packageFileFindFilesSearchPattern0": "ms-resource:loc.messages.packageFileFindFilesSearchPattern0", + "packageFile0": "ms-resource:loc.messages.packageFile0", + "Runningmsdeploycommand0": "ms-resource:loc.messages.Runningmsdeploycommand0", + "msdeploycommandransuccessfully": "ms-resource:loc.messages.msdeploycommandransuccessfully", + "filePathFindFilesSearchPattern0": "ms-resource:loc.messages.filePathFindFilesSearchPattern0", + "filePath0": "ms-resource:loc.messages.filePath0", + "UnabletofindpublishUrlforWebApp0": "ms-resource:loc.messages.UnabletofindpublishUrlforWebApp0" } } \ No newline at end of file diff --git a/common.json b/common.json index 0a10e6e12dd7..1d97a464dbd5 100644 --- a/common.json +++ b/common.json @@ -5,6 +5,12 @@ "dest": "ps_modules" } ], + "AzureRMWebAppDeployment": [ + { + "module": "VstsAzureHelpers_", + "dest": "ps_modules" + } + ], "MSBuild": [ { "module": "MSBuildHelpers",