Skip to content

Commit

Permalink
resolved merge conflicts #2
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent1173 committed Jul 24, 2018
2 parents 4d6722d + 6789486 commit 0abdce3
Show file tree
Hide file tree
Showing 50 changed files with 1,247 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class PublishProfileWebAppDeploymentProvider implements IWebAppDeployment
}

private GetDeployCmdFilePath(): string {
var webPackagePath = packageUtility.PackageUtility.getPackagePath(this.taskParams.Package);
var webPackagePath = this.taskParams.Package.getPath();
var packageDir = path.dirname(webPackagePath);
return packageUtility.PackageUtility.getPackagePath(packageDir + "\\*.deploy.cmd");
}
Expand Down
25 changes: 9 additions & 16 deletions Tasks/AzureRmWebAppDeploymentV4/operations/KuduServiceUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ export class KuduServiceUtility {
}

public async runPostDeploymentScript(taskParams: TaskParameters, directoryPath?: string): Promise<void> {
var uniqueID = this.getDeploymentID();
let vstsPostDeploymentFolderPath: string = path.join(physicalRootPath.substring(1), '..', 'VSTS_PostDeployment_' + uniqueID);
try {
var uniqueID = this.getDeploymentID();
var createNewFolder = false;
var rootDirectoryPath = directoryPath;
if(!directoryPath) {
rootDirectoryPath = physicalRootPath.substring(1);
directoryPath = path.join(physicalRootPath.substring(1), '..', 'VSTS_PostDeployment_' + uniqueID);
createNewFolder = true;
}
var rootDirectoryPath = directoryPath || physicalRootPath.substring(1);

if(taskParams.TakeAppOfflineFlag) {
await this._appOfflineKuduService(rootDirectoryPath, true);
Expand All @@ -56,8 +51,8 @@ export class KuduServiceUtility {
var scriptFile = this._getPostDeploymentScript(taskParams.ScriptType, taskParams.InlineScript, taskParams.ScriptPath, taskParams.isLinuxApp);
var fileExtension : string = taskParams.isLinuxApp ? '.sh' : '.cmd';
var mainCmdFilePath = path.join(__dirname, '..', 'postDeploymentScript', 'mainCmdFile' + fileExtension);
await this._appServiceKuduService.uploadFile(directoryPath, 'mainCmdFile' + fileExtension, mainCmdFilePath);
await this._appServiceKuduService.uploadFile(directoryPath, 'kuduPostDeploymentScript' + fileExtension, scriptFile.filePath);
await this._appServiceKuduService.uploadFile(vstsPostDeploymentFolderPath, 'mainCmdFile' + fileExtension, mainCmdFilePath);
await this._appServiceKuduService.uploadFile(vstsPostDeploymentFolderPath, 'kuduPostDeploymentScript' + fileExtension, scriptFile.filePath);
console.log(tl.loc('ExecuteScriptOnKudu'));
var cmdFilePath = '%Home%\\site\\VSTS_PostDeployment_' + uniqueID + '\\mainCmdFile' + fileExtension;
var scriprResultPath = '%Home%\\site\\VSTS_PostDeployment_' + uniqueID + '\\script_result.txt';
Expand All @@ -66,7 +61,7 @@ export class KuduServiceUtility {
scriprResultPath = '/home/site/VSTS_PostDeployment_' + uniqueID + '/script_result.txt';
}
await this.runCommand(rootDirectoryPath, cmdFilePath + ' ' + uniqueID, 30, scriprResultPath);
await this._printPostDeploymentLogs(directoryPath);
await this._printPostDeploymentLogs(vstsPostDeploymentFolderPath);

}
catch(error) {
Expand All @@ -83,11 +78,9 @@ export class KuduServiceUtility {
}
finally {
try {
await this._appServiceKuduService.uploadFile(directoryPath, 'delete_log_file' + fileExtension, path.join(__dirname, '..', 'postDeploymentScript', 'deleteLogFile' + fileExtension));
await this.runCommand(directoryPath, 'delete_log_file' + fileExtension, 0, null);
if(createNewFolder) {
await this._appServiceKuduService.deleteFolder(directoryPath);
}
await this._appServiceKuduService.uploadFile(vstsPostDeploymentFolderPath, 'delete_log_file' + fileExtension, path.join(__dirname, '..', 'postDeploymentScript', 'deleteLogFile' + fileExtension));
await this.runCommand(vstsPostDeploymentFolderPath, 'delete_log_file' + fileExtension, 0, null);
await this._appServiceKuduService.deleteFolder(vstsPostDeploymentFolderPath);
}
catch(error) {
tl.debug('Unable to delete log files : ' + error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class TaskParametersUtility {
private static _initializeDefaultParametersForPublishProfile(taskParameters: TaskParameters): void {
taskParameters.PublishProfilePath = tl.getInput('PublishProfilePath', true);
taskParameters.PublishProfilePassword = tl.getInput('PublishProfilePassword', true);
taskParameters.Package = new Package(tl.getPathInput('Package', true));
taskParameters.AdditionalArguments = "-retryAttempts:6 -retryInterval:10000";
}

Expand Down
38 changes: 0 additions & 38 deletions Tasks/Common/Deployment/TelemetryHelper/TelemetryHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,44 +36,6 @@ function Write-Telemetry
Write-Host $telemetryString
}

function Get-ExceptionData
{
param(
[System.Management.Automation.ErrorRecord]
$error
)

$exceptionData = ""
try
{
$src = $error.InvocationInfo.PSCommandPath + "|" + $error.InvocationInfo.ScriptLineNumber
$exceptionTypes = ""

$exception = $error.Exception
if ($exception.GetType().Name -eq 'AggregateException')
{
$flattenedException = ([System.AggregateException]$exception).Flatten()
$flattenedException.InnerExceptions | ForEach-Object {
$exceptionTypes += $_.GetType().FullName + ";"
}
}
else
{
do
{
$exceptionTypes += $exception.GetType().FullName + ";"
$exception = $exception.InnerException
} while ($exception -ne $null)
}
$exceptionData = "$exceptionTypes|$src"
}
catch
{}

return $exceptionData
}

# Export only the public function.
Export-ModuleMember -Function Write-Telemetry
Export-ModuleMember -Function Get-ExceptionData
Export-ModuleMember -Variable telemetryCodes
27 changes: 12 additions & 15 deletions Tasks/Common/PowershellHelpers/Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ function Invoke-ActionWithRetries
$RetryMessage
)

Trace-VstsEnteringInvocation $MyInvocation

if (!$RetryMessage)
{
$RetryMessage = Get-VstsLocString -Key RetryAfterMessage $RetryIntervalInSeconds
}

$lastResult = $null;
$retryIteration = 1
do
{
Expand All @@ -42,11 +36,12 @@ function Invoke-ActionWithRetries

try
{
$result = & $Action
$result = & $Action $lastResult
$lastResult = $result
}
catch
{
if (($null -eq $RetryableExceptions) -or (Test-RetryableException -Exception $_.Exception -AllowedExceptions $RetryableExceptions))
if (($null -eq $RetryableExceptions) -or (Test-RetryableException -Exception $_.Exception -RetryableExceptions $RetryableExceptions))
{
$shouldRetry = $ExceptionRetryEvaluator.Invoke($_.Exception)
if (!$shouldRetry)
Expand Down Expand Up @@ -80,12 +75,14 @@ function Invoke-ActionWithRetries
}
}

Write-Host $RetryMessage
if ($RetryMessage)
{
Write-Host $RetryMessage
}

$retryIteration++
Start-Sleep $RetryIntervalInSeconds
} while ($true)

Trace-VstsLeavingInvocation $MyInvocation
}

function Get-TempDirectoryPath
Expand Down Expand Up @@ -115,15 +112,15 @@ function Test-RetryableException
$Exception,

[string[]]
$AllowedExceptions
$RetryableExceptions
)

$AllowedExceptions | ForEach-Object {
$RetryableExceptions | ForEach-Object {
if ($_ -and ($Exception -is ([type]$_)))
{
return $true;
}
}

return $false
}
}
67 changes: 67 additions & 0 deletions Tasks/Common/ServiceFabricHelpers/CommonHelpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function Publish-Telemetry
{
Param (
[String]
$TaskName,

[String]
$OperationId,

[System.Management.Automation.ErrorRecord]
$ErrorData
)

try
{
$telemetryData = @{
'OperationId' = $OperationId
'ExceptionData' = (Get-ExceptionData $ErrorData)
'JobId' = (Get-VstsTaskVariable -Name 'System.JobId')
}

$telemetryJson = ConvertTo-Json $telemetryData -Compress
Write-Host "##vso[telemetry.publish area=TaskHub;feature=$TaskName]$telemetryJson"
}
catch
{
# suppress
Write-Warning (Get-VstsLocString -Key TelemetryWarning -ArgumentList $_)
}
}

function Get-ExceptionData
{
param(
[System.Management.Automation.ErrorRecord]
$error
)

$exceptionData = ""
try
{
$src = $error.InvocationInfo.PSCommandPath + "|" + $error.InvocationInfo.ScriptLineNumber
$exceptionTypes = ""

$exception = $error.Exception
if ($exception.GetType().Name -eq 'AggregateException')
{
$flattenedException = ([System.AggregateException]$exception).Flatten()
$flattenedException.InnerExceptions | ForEach-Object {
$exceptionTypes += $_.GetType().FullName + ";"
}
}
else
{
do
{
$exceptionTypes += $exception.GetType().FullName + ";"
$exception = $exception.InnerException
} while ($exception -ne $null)
}
$exceptionData = "$exceptionTypes|$src"
}
catch
{}

return $exceptionData
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Get-AadSecurityToken

# Query cluster metadata
$global:operationId = $SF_Operations.ConnectClusterMetadata
$connectResult = Connect-ServiceFabricCluster @connectionParametersWithGetMetadata
$connectResult = Connect-ServiceFabricClusterAction -ClusterConnectionParameters $connectionParametersWithGetMetadata
$authority = $connectResult.AzureActiveDirectoryMetadata.Authority
Write-Host (Get-VstsLocString -Key AadAuthority -ArgumentList $authority)
$clusterApplicationId = $connectResult.AzureActiveDirectoryMetadata.ClusterApplication
Expand Down Expand Up @@ -80,7 +80,7 @@ function Add-Certificate

# Explicitly set the key storage to use UserKeySet. This will ensure the private key is stored in a folder location which the user has access to.
# If we don't explicitly set it to UserKeySet, it's possible the MachineKeySet will be used which the user doesn't have access to that folder location, resulting in an access denied error.
$certificate.Import($bytes, $certPassword, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::UserKeySet)
$certificate.Import($bytes, $certPassword, "PersistKeySet,UserKeySet")
}
catch
{
Expand Down Expand Up @@ -110,6 +110,29 @@ function Add-Certificate

return $certificate
}
function Remove-ClientCertificate
{
[CmdletBinding()]
Param (
$Certificate
)

try
{
if ($null -ne $Certificate)
{
$thumbprint = $Certificate.Thumbprint
if (Test-Path "Cert:\CurrentUser\My\$thumbprint")
{
Remove-Item "Cert:\CurrentUser\My\$thumbprint" -Force
}
}
}
catch
{
Write-Warning (Get-VstsLocString -Key WarningOnRemoveCertificate -ArgumentList $_)
}
}
function Connect-ServiceFabricClusterFromServiceEndpoint
{
[CmdletBinding()]
Expand All @@ -123,11 +146,12 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
Trace-VstsEnteringInvocation $MyInvocation

Import-Module $PSScriptRoot/../TlsHelper_
Import-Module $PSScriptRoot/../PowershellHelpers
Add-Tls12InSession

try
{

$certificate = $null
$regKey = "HKLM:\SOFTWARE\Microsoft\Service Fabric SDK"
if (!(Test-Path $regKey))
{
Expand Down Expand Up @@ -160,7 +184,7 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
}
elseif ($ConnectedServiceEndpoint.Auth.Scheme -eq "Certificate")
{
Add-Certificate -ClusterConnectionParameters $clusterConnectionParameters -ConnectedServiceEndpoint $ConnectedServiceEndpoint
$certificate = Add-Certificate -ClusterConnectionParameters $clusterConnectionParameters -ConnectedServiceEndpoint $ConnectedServiceEndpoint
$clusterConnectionParameters["X509Credential"] = $true
}
}
Expand All @@ -183,7 +207,8 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
$global:operationId = $SF_Operations.ConnectCluster
try
{
[void](Connect-ServiceFabricCluster @clusterConnectionParameters)
[void](Connect-ServiceFabricClusterAction -ClusterConnectionParameters $clusterConnectionParameters)
return $certificate
}
catch
{
Expand All @@ -195,11 +220,6 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
throw $_
}

Write-Host (Get-VstsLocString -Key ConnectedToCluster)

# Reset the scope of the ClusterConnection variable that gets set by the call to Connect-ServiceFabricCluster so that it is available outside the scope of this module
Set-Variable -Name ClusterConnection -Value $Private:ClusterConnection -Scope Global

}
catch
{
Expand All @@ -210,4 +230,35 @@ function Connect-ServiceFabricClusterFromServiceEndpoint
{
Trace-VstsLeavingInvocation $MyInvocation
}
}

function Connect-ServiceFabricClusterAction
{
param(
[Hashtable]
$ClusterConnectionParameters
)

$connectResult = $null

try
{
# Call a trial Connect-ServiceFabricCluster first so that ServiceFabric PS module gets loaded. Retry only if this connect fails.
$connectResult = Connect-ServiceFabricCluster @clusterConnectionParameters
}
catch [System.Fabric.FabricTransientException], [System.TimeoutException]
{
$connectAction = { Connect-ServiceFabricCluster @clusterConnectionParameters }
$connectResult = Invoke-ActionWithRetries -Action $connectAction `
-MaxTries 3 `
-RetryIntervalInSeconds 10 `
-RetryableExceptions @("System.Fabric.FabricTransientException", "System.TimeoutException") `
-RetryMessage (Get-VstsLocString -Key RetryingClusterConnection)
}

Write-Host (Get-VstsLocString -Key ConnectedToCluster)

# Reset the scope of the ClusterConnection variable that gets set by the call to Connect-ServiceFabricCluster so that it is available outside the scope of this module
Set-Variable -Name ClusterConnection -Value $Private:ClusterConnection -Scope Global
return $connectResult
}
1 change: 1 addition & 0 deletions Tasks/Common/ServiceFabricHelpers/SFOperations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ $SF_Operations = @{
CreateNewApplication = 'CreateNewApplication'
StartApplicationUpgrade = 'StartApplicationUpgrade';
GetApplicationUpgradeStatus = 'GetApplicationUpgradeStatus';
WaitApplicationUpgradeStatus = 'WaitApplicationUpgradeStatus';
EncryptServiceFabricText = 'EncryptServiceFabricText';
CreateDiffPackage = 'CreateDiffPackage';
GetComposeDeploymentStatus = 'GetComposeDeploymentStatus';
Expand Down
Loading

0 comments on commit 0abdce3

Please sign in to comment.