Skip to content

Commit c1f1433

Browse files
vthiebaut10andyleejordan
authored andcommitted
Refactor environment variable setup
1 parent bb646e2 commit c1f1433

File tree

1 file changed

+13
-42
lines changed

1 file changed

+13
-42
lines changed

.pipelines/SecretManagement-Official.yml

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ extends:
217217
- download: current
218218
displayName: Download artifacts
219219
- task: CopyFiles@2
220-
SourceFolder: $(drop)
221-
Contents: Microsoft.PowerShell.SecretManagement.$(version).nupkg
222-
TargetFolder: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/SrcFiles/
220+
SourceFolder: $(drop)
221+
Contents: Microsoft.PowerShell.SecretManagement.$(version).nupkg
222+
TargetFolder: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/SrcFiles/
223223
- task: ArchiveFiles@2
224224
inputs:
225225
rootFolderOrFile: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/Shell/Run
@@ -229,54 +229,25 @@ extends:
229229
archiveFile: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/Shell/Run.tar
230230
displayName: Compress Run script into tar file as needed for EV2 Shell extension
231231
- pwsh: |
232-
$pathToJsonFile = Join-Path -Path '$(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot' -ChildPath 'SecretManagementToACR.Rollout.json'
232+
$pathToJsonFile = '$(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/SecretManagementToACR.Rollout.json'
233233
$content = Get-Content -Path $pathToJsonFile | ConvertFrom-Json
234-
$envVarArrayLen = $content.shellExtensions.launch.environmentVariables.Length
235234
236-
[xml]$xml = Get-Content Directory.Build.props
237-
$version = $xml.Project.PropertyGroup.ModuleVersion
235+
$environmentVariables = @()
238236
239-
for ($i=0; $i -lt $envVarArrayLen; $i++)
240-
{
241-
$name = $($content.shellExtensions.launch.environmentVariables[$i].name)
242-
if ($name -eq "DESTINATION_ACR_NAME")
243-
{
244-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(acr_name)'
245-
Write-Verbose -Verbose "ACR Name: $($content.shellExtensions.launch.environmentVariables[$i].value)"
246-
}
247-
elseif ($name -eq "DESTINATION_ACR_URI")
248-
{
249-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(acr_uri)'
250-
Write-Verbose -Verbose "ACR URI: $($content.shellExtensions.launch.environmentVariables[$i].value)"
251-
}
252-
elseif ($name -eq "MI_NAME")
253-
{
254-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(managed_identity_name)'
255-
Write-Verbose -Verbose "MI Name: $($content.shellExtensions.launch.environmentVariables[$i].value)"
256-
}
257-
elseif ($name -eq "MI_CLIENTID")
258-
{
259-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(managed_identity_clientid)'
260-
Write-Verbose -Verbose "MI Client ID: $($content.shellExtensions.launch.environmentVariables[$i].value)"
261-
}
262-
elseif($name -eq "SECRET_MANAGEMENT_VERSION")
263-
{
264-
$content.shellExtensions.launch.environmentVariables[$i].value = $version
265-
Write-Verbose -Verbose "Module version: $($content.shellExtensions.launch.environmentVariables[$i].value)"
266-
}
267-
elseif($name -eq "SECRET_MANAGEMENT_MODULE")
268-
{
269-
$content.shellExtensions.launch.environmentVariables[$i].reference.path = "SrcFiles\\Microsoft.PowerShell.SecretManagement.$(version).nupkg"
270-
Write-Verbose -Verbose "Module Path: $($content.shellExtensions.launch.environmentVariables[$i].reference.path)"
271-
}
272-
}
237+
$environmentVariables += [PSCustomObject]@{name="DESTINATION_ACR_NAME", value='$(acr_name)'}
238+
$environmentVariables += [PSCustomObject]@{name="DESTINATION_ACR_URI", value='$(acr_uri)'}
239+
$environmentVariables += [PSCustomObject]@{name="MI_NAME", value='$(managed_identity_name)'}
240+
$environmentVariables += [PSCustomObject]@{name="MI_CLIENTID", value='$(managed_identity_clientid)'}
241+
$environmentVariables += [PSCustomObject]@{name="SECRET_MANAGEMENT_VERSION", value='$(version)'}
242+
$environmentVariables += [PSCustomObject]@{name="SECRET_MANAGEMENT_MODULE", reference=[PSCustomObject]@{path="SrcFiles\\Microsoft.PowerShell.SecretManagement.$(version).nupkg"}'}
243+
244+
$content.shellExtensions.launch.environmentVariables = $environmentVariables
273245
274246
$identityString = "/subscriptions/$(acr_subscription)/resourcegroups/$(acr_resource_group)/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$(managed_identity_name)"
275247
$content.shellExtensions.launch.identity.userAssignedIdentities[0] = $identityString
276248
277249
Remove-Item -Path $pathToJsonFile
278250
$content | ConvertTo-Json -Depth 6 | Out-File $pathToJsonFile
279-
280251
displayName: 'Replace values in SecretManagementToACR.Rollout.json file'
281252
- pwsh: |
282253
$pathToJsonFile = Join-Path -Path '$(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot' -ChildPath 'RolloutSpec.json'

0 commit comments

Comments
 (0)