Skip to content

Commit e94ae46

Browse files
committed
Refactor environment variable setup
1 parent 89483ed commit e94ae46

1 file changed

Lines changed: 13 additions & 42 deletions

File tree

.pipelines/SecretManagement-Official.yml

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ extends:
220220
- download: current
221221
displayName: Download artifacts
222222
- task: CopyFiles@2
223-
SourceFolder: $(drop)
224-
Contents: Microsoft.PowerShell.SecretManagement.$(version).nupkg
225-
TargetFolder: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/SrcFiles/
223+
SourceFolder: $(drop)
224+
Contents: Microsoft.PowerShell.SecretManagement.$(version).nupkg
225+
TargetFolder: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/SrcFiles/
226226
- task: ArchiveFiles@2
227227
inputs:
228228
rootFolderOrFile: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/Shell/Run
@@ -232,54 +232,25 @@ extends:
232232
archiveFile: $(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/Shell/Run.tar
233233
displayName: Compress Run script into tar file as needed for EV2 Shell extension
234234
- pwsh: |
235-
$pathToJsonFile = Join-Path -Path '$(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot' -ChildPath 'SecretManagementToACR.Rollout.json'
235+
$pathToJsonFile = '$(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot/SecretManagementToACR.Rollout.json'
236236
$content = Get-Content -Path $pathToJsonFile | ConvertFrom-Json
237-
$envVarArrayLen = $content.shellExtensions.launch.environmentVariables.Length
238237
239-
[xml]$xml = Get-Content Directory.Build.props
240-
$version = $xml.Project.PropertyGroup.ModuleVersion
238+
$environmentVariables = @()
241239
242-
for ($i=0; $i -lt $envVarArrayLen; $i++)
243-
{
244-
$name = $($content.shellExtensions.launch.environmentVariables[$i].name)
245-
if ($name -eq "DESTINATION_ACR_NAME")
246-
{
247-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(acr_name)'
248-
Write-Verbose -Verbose "ACR Name: $($content.shellExtensions.launch.environmentVariables[$i].value)"
249-
}
250-
elseif ($name -eq "DESTINATION_ACR_URI")
251-
{
252-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(acr_uri)'
253-
Write-Verbose -Verbose "ACR URI: $($content.shellExtensions.launch.environmentVariables[$i].value)"
254-
}
255-
elseif ($name -eq "MI_NAME")
256-
{
257-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(managed_identity_name)'
258-
Write-Verbose -Verbose "MI Name: $($content.shellExtensions.launch.environmentVariables[$i].value)"
259-
}
260-
elseif ($name -eq "MI_CLIENTID")
261-
{
262-
$content.shellExtensions.launch.environmentVariables[$i].value = '$(managed_identity_clientid)'
263-
Write-Verbose -Verbose "MI Client ID: $($content.shellExtensions.launch.environmentVariables[$i].value)"
264-
}
265-
elseif($name -eq "SECRET_MANAGEMENT_VERSION")
266-
{
267-
$content.shellExtensions.launch.environmentVariables[$i].value = $version
268-
Write-Verbose -Verbose "Module version: $($content.shellExtensions.launch.environmentVariables[$i].value)"
269-
}
270-
elseif($name -eq "SECRET_MANAGEMENT_MODULE")
271-
{
272-
$content.shellExtensions.launch.environmentVariables[$i].reference.path = "SrcFiles\\Microsoft.PowerShell.SecretManagement.$(version).nupkg"
273-
Write-Verbose -Verbose "Module Path: $($content.shellExtensions.launch.environmentVariables[$i].reference.path)"
274-
}
275-
}
240+
$environmentVariables += [PSCustomObject]@{name="DESTINATION_ACR_NAME", value='$(acr_name)'}
241+
$environmentVariables += [PSCustomObject]@{name="DESTINATION_ACR_URI", value='$(acr_uri)'}
242+
$environmentVariables += [PSCustomObject]@{name="MI_NAME", value='$(managed_identity_name)'}
243+
$environmentVariables += [PSCustomObject]@{name="MI_CLIENTID", value='$(managed_identity_clientid)'}
244+
$environmentVariables += [PSCustomObject]@{name="SECRET_MANAGEMENT_VERSION", value='$(version)'}
245+
$environmentVariables += [PSCustomObject]@{name="SECRET_MANAGEMENT_MODULE", reference=[PSCustomObject]@{path="SrcFiles\\Microsoft.PowerShell.SecretManagement.$(version).nupkg"}'}
246+
247+
$content.shellExtensions.launch.environmentVariables = $environmentVariables
276248
277249
$identityString = "/subscriptions/$(acr_subscription)/resourcegroups/$(acr_resource_group)/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$(managed_identity_name)"
278250
$content.shellExtensions.launch.identity.userAssignedIdentities[0] = $identityString
279251
280252
Remove-Item -Path $pathToJsonFile
281253
$content | ConvertTo-Json -Depth 6 | Out-File $pathToJsonFile
282-
283254
displayName: 'Replace values in SecretManagementToACR.Rollout.json file'
284255
- pwsh: |
285256
$pathToJsonFile = Join-Path -Path '$(Build.SourcesDirectory)/EV2Specs/ServiceGroupRoot' -ChildPath 'RolloutSpec.json'

0 commit comments

Comments
 (0)