@@ -93,6 +93,11 @@ param (
93
93
})]
94
94
[array ] $AllowIpRanges = @ (),
95
95
96
+ # Instead of running the post script, create a wrapped file to run it with parameters
97
+ # so that CI can run it in a subsequent step with a refreshed azure login
98
+ [Parameter ()]
99
+ [string ] $SelfContainedPostScript ,
100
+
96
101
[Parameter ()]
97
102
[switch ] $CI = ($null -ne $env: SYSTEM_TEAMPROJECTID ),
98
103
@@ -626,8 +631,36 @@ try {
626
631
627
632
$postDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path - ChildPath " $ResourceType -resources-post.ps1"
628
633
if (Test-Path $postDeploymentScript ) {
629
- Log " Invoking post-deployment script '$postDeploymentScript '"
630
- & $postDeploymentScript - ResourceGroupName $ResourceGroupName - DeploymentOutputs $deploymentOutputs @PSBoundParameters
634
+ if ($SelfContainedPostScript ) {
635
+ Log " Creating invokable post-deployment script '$SelfContainedPostScript ' from '$postDeploymentScript '"
636
+
637
+ $deserialized = @ {}
638
+ foreach ($parameter in $PSBoundParameters.GetEnumerator ()) {
639
+ if ($parameter.Value -is [System.Management.Automation.SwitchParameter ]) {
640
+ $deserialized [$parameter.Key ] = $parameter.Value.ToBool ()
641
+ } else {
642
+ $deserialized [$parameter.Key ] = $parameter.Value
643
+ }
644
+ }
645
+ $deserialized [' ResourceGroupName' ] = $ResourceGroupName
646
+ $deserialized [' DeploymentOutputs' ] = $deploymentOutputs
647
+ $serialized = $deserialized | ConvertTo-Json
648
+
649
+ $outScript = @"
650
+ `$ parameters = `@'
651
+ $serialized
652
+ '`@ | ConvertFrom-Json -AsHashtable
653
+ # Set global variables that aren't always passed as parameters
654
+ `$ ResourceGroupName = `$ parameters.ResourceGroupName
655
+ `$ DeploymentOutputs = `$ parameters.DeploymentOutputs
656
+ $postDeploymentScript `@parameters
657
+ "@
658
+ $outScript | Out-File $SelfContainedPostScript
659
+ LogVsoCommand " ##vso[task.setvariable variable=SELF_CONTAINED_TEST_RESOURCES_POST_SCRIPT;]$selfContainedScript "
660
+ } else {
661
+ Log " Invoking post-deployment script '$postDeploymentScript '"
662
+ & $postDeploymentScript - ResourceGroupName $ResourceGroupName - DeploymentOutputs $deploymentOutputs @PSBoundParameters
663
+ }
631
664
}
632
665
633
666
if ($templateFile.jsonFilePath.EndsWith (' .compiled.json' )) {
0 commit comments