Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Users/ajya/azure rmwebapp task ps3 #1802

Merged
merged 13 commits into from
Jun 7, 2016
134 changes: 134 additions & 0 deletions Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment-Legacy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
param
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work. You're calling Utility.ps1 and AzureUtility.ps1 which you've updated to the new lib (calls Get-VstsLocString now).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericsciple What is correct solution to this problem ?

  • Should I create legacy class for Utility and AzureUtility too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes copying the originals to Utility-Legacy.ps1/AzureUtility-Legacy.ps1 would solve the problem. Ultimately the legacy implementation should be deleted in a sprint or two after it's served it's purpose.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericsciple - Thanks eric , I have done changes and have verified it .

(
[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"
183 changes: 78 additions & 105 deletions Tasks/AzureRmWebAppDeployment/AzureRmWebAppDeployment.ps1
Original file line number Diff line number Diff line change
@@ -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) ){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi - simpler powershell syntax is if (!$Package)

also fyi - I think the web UI already trims values on save. The double-quotes issue is interesting, although I have never trimmed it in tasks before, and haven't heard any issues. Just a thought.

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))
Copy link
Contributor

@ericsciple ericsciple May 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi - simpler powershell syntax is if ($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"
Loading