Skip to content

Commit 40bf70b

Browse files
Fix issues of Publish-OSPlatformSolution with two step publishing (#140)
* Fix issue with using the Wait parameter that also enabled Two Step Publish and improve support for it * Improve TwoStepMode switch name. Fix typo. * Fix name of parameter in comments * Add tests * Improve tests * Fix tests * Fix tests * Fix UseTwoStepMode parameter name in documentation and comments
1 parent 3326582 commit 40bf70b

File tree

2 files changed

+363
-24
lines changed

2 files changed

+363
-24
lines changed

src/Outsystems.SetupTools/Functions/Publish-OSPlatformSolution.ps1

Lines changed: 78 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ function Publish-OSPlatformSolution
1818
Username or PSCredential object with credentials for Service Center. If not specified defaults to admin/admin
1919
2020
.PARAMETER Wait
21-
Will waits for the deployment to finish and reports back the deployment result
21+
Will wait for the deployment to finish and reports back the deployment result
2222
2323
.PARAMETER StopOnWarnings
2424
Treat warnings as errors. Deployment will stop on compilation warnings and return success false
2525
26+
.PARAMETER UseTwoStepMode
27+
Enable 2-Stage Deployment of solution. First step compiles and prepares apps, second step deploys.
28+
29+
.PARAMETER StartSecondStep
30+
Automatically start second step of solution publish to deploy apps. Requires the UseTwoStepMode parameter.
31+
2632
.EXAMPLE
2733
$Credential = Get-Credential
2834
Publish-OSPlatformSolution -ServiceCenterHost "8.8.8.8" -Solution 'c:\solution.osp' -Credential $Credential
@@ -36,6 +42,10 @@ function Publish-OSPlatformSolution
3642
$Credential = Get-Credential
3743
Publish-OSPlatformSolution -ServiceCenterHost "8.8.8.8" -Solution 'c:\solution.osp' -Credential $Credential -StopOnWarnings
3844
45+
.EXAMPLE
46+
$Credential = Get-Credential
47+
Publish-OSPlatformSolution -ServiceCenterHost "8.8.8.8" -Solution 'c:\solution.osp' -Credential $Credential -Wait -UseTwoStepMode
48+
3949
.NOTES
4050
You can run this cmdlet on any machine with HTTP access to Service Center.
4151
@@ -50,28 +60,40 @@ function Publish-OSPlatformSolution
5060
5161
#>
5262

53-
[CmdletBinding()]
63+
[CmdletBinding(DefaultParameterSetName = 'Default')]
5464
[OutputType('Outsystems.SetupTools.PublishResult')]
5565
param (
56-
[Parameter()]
66+
[Parameter(ParameterSetName = "Default")]
67+
[Parameter(ParameterSetName = "TwoStep")]
5768
[ValidateNotNullOrEmpty()]
5869
[Alias('Host', 'Environment','ServiceCenterHost')]
5970
[string]$ServiceCenter = '127.0.0.1',
6071

61-
[Parameter(ValueFromPipeline)]
72+
[Parameter(ParameterSetName = "Default", ValueFromPipeline)]
73+
[Parameter(ParameterSetName = "TwoStep", ValueFromPipeline)]
6274
[ValidateNotNullOrEmpty()]
6375
[string]$Solution,
6476

65-
[Parameter()]
77+
[Parameter(ParameterSetName = "Default")]
78+
[Parameter(ParameterSetName = "TwoStep")]
6679
[ValidateNotNullOrEmpty()]
6780
[System.Management.Automation.Credential()]
6881
[System.Management.Automation.PSCredential]$Credential = $OSSCCred,
6982

70-
[Parameter()]
83+
[Parameter(ParameterSetName = "TwoStep")]
84+
[Parameter(ParameterSetName = "Default")]
7185
[switch]$Wait,
7286

73-
[Parameter()]
74-
[switch]$StopOnWarnings
87+
[Parameter(ParameterSetName = "Default")]
88+
[Parameter(ParameterSetName = "TwoStep")]
89+
[switch]$StopOnWarnings,
90+
91+
[Parameter(ParameterSetName = "Default")]
92+
[Parameter(ParameterSetName = "TwoStep", Mandatory = $true)]
93+
[switch]$UseTwoStepMode,
94+
95+
[Parameter(ParameterSetName = "TwoStep")]
96+
[switch]$StartSecondStep
7597
)
7698

7799
begin
@@ -89,6 +111,7 @@ function Publish-OSPlatformSolution
89111
ExitCode = 0
90112
Message = ''
91113
}
114+
92115
}
93116

94117
process
@@ -107,13 +130,26 @@ function Publish-OSPlatformSolution
107130

108131
return $publishResult
109132
}
133+
134+
# Check if StartSecondStep switch was enabled but UseTwoStepMode was not
135+
if ( ($StartSecondStep -eq $true) -and ($UseTwoStepMode -eq $false) )
136+
{
137+
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 3 -Message "Error in parameters provided. StartSecondStep enabled requires that UseTwoStepMode is also enabled" -Exception $_.Exception
138+
WriteNonTerminalError -Message "Error in parameters provided"
139+
140+
$publishResult.Success = $false
141+
$publishResult.ExitCode = -1
142+
$publishResult.Message = "Error in parameters provided"
143+
144+
return $publishResult
145+
}
110146
#endregion
111147

112148
#region start publish step 1
113149
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Uploading solution $Solution"
114150
try
115151
{
116-
$publishAsyncResult = AppMgmt_SolutionPublish -SCHost $ServiceCenter -Solution $Solution -Credential $Credential -TwoStepMode $Wait -CallingFunction $($MyInvocation.Mycommand)
152+
$publishAsyncResult = AppMgmt_SolutionPublish -SCHost $ServiceCenter -Solution $Solution -Credential $Credential -TwoStepMode $UseTwoStepMode -CallingFunction $($MyInvocation.Mycommand)
117153
}
118154
catch
119155
{
@@ -201,24 +237,40 @@ function Publish-OSPlatformSolution
201237
return $publishResult
202238
}
203239
#endregion
240+
241+
#region handle two step publishing enabled
242+
if ( ($UseTwoStepMode.IsPresent -eq $true) -and ($StartSecondStep.IsPresent -eq $false) ) {
204243

205-
#region start publish step 2
206-
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Continuing to the deployment..."
207-
try
208-
{
209-
AppMgmt_SolutionPublishContinue -SCHost $ServiceCenter -PublishId $publishId -Credential $Credential -CallingFunction $($MyInvocation.Mycommand)
210-
}
211-
catch
212-
{
213-
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 3 -Message "Error while starting to deploy the solution" -Exception $_.Exception
214-
WriteNonTerminalError -Message "Error while starting to deploy the solution"
215-
216-
$publishResult.Success = $false
244+
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "First step of solution publish successfully completed. Will wait for second step to be be started in Service Center to finish deployment"
245+
$publishResult.Message = "First step of solution publish successfully completed. Will wait for second step to be be started in Service Center to finish deployment."
217246
$publishResult.PublishId = $publishId
218-
$publishResult.ExitCode = -1
219-
$publishResult.Message = "Error while starting to deploy the solution"
220247

221248
return $publishResult
249+
250+
}
251+
252+
elseif ( ($UseTwoStepMode.IsPresent -eq $true) -and ($StartSecondStep.IsPresent -eq $true) ) {
253+
254+
#region start publish step 2
255+
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Continuing to the deployment..."
256+
try
257+
{
258+
AppMgmt_SolutionPublishContinue -SCHost $ServiceCenter -PublishId $publishId -Credential $Credential -CallingFunction $($MyInvocation.Mycommand)
259+
}
260+
catch
261+
{
262+
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 3 -Message "Error while starting to deploy the solution" -Exception $_.Exception
263+
WriteNonTerminalError -Message "Error while starting to deploy the solution"
264+
265+
$publishResult.Success = $false
266+
$publishResult.PublishId = $publishId
267+
$publishResult.ExitCode = -1
268+
$publishResult.Message = "Error while starting to deploy the solution"
269+
270+
return $publishResult
271+
}
272+
#endregion
273+
222274
}
223275
#endregion
224276

@@ -276,13 +328,15 @@ function Publish-OSPlatformSolution
276328

277329
return $publishResult
278330
}
279-
#endregion
280331

281332
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Solution successfully published"
282333
$publishResult.Message = "Solution successfully published"
283334
$publishResult.PublishId = $publishId
284335

285336
return $publishResult
337+
338+
#endregion
339+
286340
}
287341

288342
end

0 commit comments

Comments
 (0)