Skip to content

Commit

Permalink
Added Async Timeout option when importing solution in script and task
Browse files Browse the repository at this point in the history
  • Loading branch information
WaelHamze committed Jan 31, 2017
1 parent 5e2dcbf commit af18784
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ public class ImportXrmSolutionCommand : XrmCommandBase

public ImportXrmSolutionCommand()
{
AsyncWaitTimeout = 15 * 60;
SleepInterval = 15;
}

#endregion
Expand All @@ -111,6 +109,18 @@ protected override void ProcessRecord()
ImportJobId = Guid.NewGuid();
}

if (AsyncWaitTimeout == 0)
{
AsyncWaitTimeout = 15 * 60;
base.WriteVerbose(string.Format("Setting Default AsyncWaitTimeout: {0}", AsyncWaitTimeout));
}

if (SleepInterval == 0)
{
SleepInterval = 15;
base.WriteVerbose(string.Format("Setting Default SleepInterval: {0}", SleepInterval));
}

base.WriteVerbose(string.Format("ImportJobId {0}", ImportJobId));

byte[] solutionBytes = File.ReadAllBytes(SolutionFilePath);
Expand Down Expand Up @@ -166,6 +176,7 @@ private void AwaitCompletion(Guid asyncJobId)
}

Thread.Sleep(SleepInterval * 1000);
base.WriteVerbose(string.Format("Sleeping for {0} seconds", SleepInterval));

AsyncOperation asyncOperation;

Expand All @@ -180,6 +191,8 @@ private void AwaitCompletion(Guid asyncJobId)
continue;
}

base.WriteVerbose(string.Format("StatusCode: {0}", asyncOperation.StatusCode.Value));

switch (asyncOperation.StatusCode.Value)
{
//Succeeded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ param(
[bool]$skipProductUpdateDependencies, #Will skip product update dependencies
[bool]$convertToManaged, #Direct the system to convert any matching unmanaged customizations into your managed solution. Optional.
[bool]$holdingSolution,
[int]$AsyncWaitTimeout, #Optional - Async wait timeout in seconds
[string]$logsDirectory, #Optional - will place the import log in here
[string]$logFilename #Optional - will use this as import log file name
)
Expand All @@ -36,6 +37,7 @@ Write-Verbose "overwriteUnmanagedCustomizations = $overwriteUnmanagedCustomizati
Write-Verbose "skipProductUpdateDependencies = $skipProductUpdateDependencies"
Write-Verbose "convertToManaged = $convertToManaged"
Write-Verbose "holdingSolution = $holdingSolution"
Write-Verbose "AsyncWaitTimeout = $AsyncWaitTimeout"
Write-Verbose "logsDirectory = $logsDirectory"
Write-Verbose "logFilename = $logFilename"

Expand Down Expand Up @@ -63,7 +65,7 @@ if ($override -or ($solution -eq $null) -or ($solution.Version -ne $solutionInfo

$importJobId = [guid]::NewGuid()

$asyncOperationId = Import-XrmSolution -ConnectionString $CrmConnectionString -SolutionFilePath $solutionFile -publishWorkflows $publishWorkflows -overwriteUnmanagedCustomizations $overwriteUnmanagedCustomizations -SkipProductUpdateDependencies $skipProductUpdateDependencies -ConvertToManaged $convertToManaged -HoldingSolution $holdingSolution -ImportAsync $true -WaitForCompletion $true -ImportJobId $importJobId -Verbose
$asyncOperationId = Import-XrmSolution -ConnectionString $CrmConnectionString -SolutionFilePath $solutionFile -publishWorkflows $publishWorkflows -overwriteUnmanagedCustomizations $overwriteUnmanagedCustomizations -SkipProductUpdateDependencies $skipProductUpdateDependencies -ConvertToManaged $convertToManaged -HoldingSolution $holdingSolution -ImportAsync $true -WaitForCompletion $true -ImportJobId $importJobId -AsyncWaitTimeout $AsyncWaitTimeout -Verbose

Write-Host "Solution Import Completed. Import Job Id: $importJobId"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "xrm-ci-framework-build-tasks",
"name": "Dynamics CRM Build Tools",
"version": "8.0.13",
"version": "8.0.14",
"publisher": "WaelHamze",
"targets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $skipProductUpdateDependencies = Get-VstsInput -Name skipProductUpdateDependenci
$convertToManaged = Get-VstsInput -Name convertToManaged -AsBool
$holdingSolution = Get-VstsInput -Name holdingSolution -AsBool
$override = Get-VstsInput -Name override -AsBool
$asyncWaitTimeout = Get-VstsInput -Name asyncWaitTimeout -Require -AsInt

#TFS Release Parameters
$artifactsFolder = $env:AGENT_RELEASEDIRECTORY
Expand All @@ -28,6 +29,7 @@ Write-Verbose "skipProductUpdateDependencies = $skipProductUpdateDependencies"
Write-Verbose "convertToManaged = $convertToManaged"
Write-Verbose "holdingSolution = $holdingSolution"
Write-Verbose "override = $override"
Write-Verbose "asyncWaitTimeout = $asyncWaitTimeout"
Write-Verbose "artifactsFolder = $artifactsFolder"

#Script Location
Expand All @@ -38,7 +40,7 @@ $solutionFilename = $solutionFile.Substring($solutionFile.LastIndexOf("\") + 1)

$logFilename = $solutionFilename.replace(".zip", "_importlog_" + [System.DateTime]::Now.ToString("yyyy_MM_dd__HH_mm") + ".xml")

& "$scriptPath\ps_modules\xRMCIFramework\ImportSolution.ps1" -solutionFile $solutionFile -crmConnectionString $CrmConnectionString -override $override -publishWorkflows $publishWorkflows -overwriteUnmanagedCustomizations $overwriteUnmanagedCustomizations -skipProductUpdateDependencies $skipProductUpdateDependencies -ConvertToManaged $convertToManaged -HoldingSolution $holdingSolution -logsDirectory "$artifactsFolder" -logFileName $logFilename
& "$scriptPath\ps_modules\xRMCIFramework\ImportSolution.ps1" -solutionFile $solutionFile -crmConnectionString $CrmConnectionString -override $override -publishWorkflows $publishWorkflows -overwriteUnmanagedCustomizations $overwriteUnmanagedCustomizations -skipProductUpdateDependencies $skipProductUpdateDependencies -ConvertToManaged $convertToManaged -HoldingSolution $holdingSolution -logsDirectory "$artifactsFolder" -logFileName $logFilename -AsyncWaitTimeout $AsyncWaitTimeout

if (Test-Path $artifactsFolder\$logFilename)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"demands": [ ],
"version": {
"Major": "8",
"Minor": "0",
"Patch": "3"
"Minor": "1",
"Patch": "1"
},
"minimumAgentVersion": "1.95.0",
"instanceNameFormat": "MSCRM Import Solution",
Expand Down Expand Up @@ -82,6 +82,14 @@
"defaultValue": "false",
"required": false,
"helpMarkDown": "If set to true will override the solution even if a solution with same version exists"
},
{
"name": "asyncWaitTimeout",
"type": "string",
"label": "Async Wait Timeout",
"defaultValue": "900",
"required": false,
"helpMarkDown": "The number of seconds to wait for async solution import to complete before timing out"
}
],
"execution": {
Expand Down

0 comments on commit af18784

Please sign in to comment.