Skip to content

Commit ecdff6d

Browse files
authored
Sync eng/common directory with azure-sdk-tools repository (Azure#1867)
1 parent fd62ba8 commit ecdff6d

37 files changed

+1027
-1759
lines changed

eng/common/TestResources/New-TestResources.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ try {
350350
# to determine whether resources should be removed.
351351
Write-Host "Setting variable 'CI_HAS_DEPLOYED_RESOURCES': 'true'"
352352
LogVsoCommand "##vso[task.setvariable variable=CI_HAS_DEPLOYED_RESOURCES;]true"
353+
# Set resource group env variable early in cases where deployment fails as we
354+
# still want to clean up the group. The Remove-TestResources.ps1 script consumes this var.
355+
$envVarName = (BuildServiceDirectoryPrefix $serviceName) + "RESOURCE_GROUP"
356+
LogVsoCommand "##vso[task.setvariable variable=$envVarName;]$ResourceGroupName"
353357
}
354358

355359
Log "Creating resource group '$ResourceGroupName' in location '$Location'"
@@ -515,9 +519,9 @@ try {
515519

516520
# Try to detect the shell based on the parent process name (e.g. launch via shebang).
517521
$shell, $shellExportFormat = if (($parentProcessName = (Get-Process -Id $PID).Parent.ProcessName) -and $parentProcessName -eq 'cmd') {
518-
'cmd', 'set {0}={1}'
522+
'cmd', 'set {0}=''{1}'''
519523
} elseif (@('bash', 'csh', 'tcsh', 'zsh') -contains $parentProcessName) {
520-
'shell', 'export {0}={1}'
524+
'shell', 'export {0}=''{1}'''
521525
} else {
522526
'PowerShell', '${{env:{0}}} = ''{1}'''
523527
}

eng/common/TestResources/SubConfig-Helpers.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,26 @@ function UpdateSubscriptionConfigurationWithFiles([object]$baseSubConfig, [strin
196196
# Helper function for processing stringified json sub configs from pipeline parameter data
197197
function BuildAndSetSubscriptionConfig([string]$baseSubConfigJson, [string]$additionalSubConfigsJson, [string]$subConfigFilesJson) {
198198
$finalConfig = @{}
199-
if ($baseSubConfigJson) {
199+
200+
if ($baseSubConfigJson -and $baseSubConfigJson -ne '""') {
201+
# When variable groups are not added to the pipeline, secret references like
202+
# $(<my secret>) are passed as a string literal instead of being replaced by the keyvault secret value
203+
if ($baseSubConfigJson -notlike '{*') {
204+
throw "Expected a json dictionary object but found '$baseSubConfigJson'. This probably means a subscription config secret was not downloaded. The pipeline is likely missing a variable group."
205+
}
200206
$baseSubConfig = $baseSubConfigJson | ConvertFrom-Json -AsHashtable
201207

202208
Write-Host "Setting base sub config"
203209
$finalConfig = SetSubscriptionConfiguration $baseSubConfig
204210
}
205211

206-
if ($additionalSubConfigsJson) {
212+
if ($additionalSubConfigsJson -and $additionalSubConfigsJson -ne '""') {
207213
$subConfigs = $additionalSubConfigsJson | ConvertFrom-Json -AsHashtable
208214

209215
foreach ($subConfig in $subConfigs) {
216+
if ($subConfig -isnot [hashtable]) {
217+
throw "Expected a json dictionary object but found '$subConfig'. This probably means a subscription config secret was not downloaded. The pipeline is likely missing a variable group."
218+
}
210219
Write-Host "Merging sub config from list"
211220
$finalConfig = UpdateSubscriptionConfiguration $finalConfig $subConfig
212221
}

eng/common/TestResources/build-test-resource-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parameters:
22
- name: SubscriptionConfiguration
33
type: string
4-
default: $(sub-config-azure-cloud-test-resources)
4+
default: '{}'
55
- name: SubscriptionConfigurations
66
type: object
77
default: null

eng/common/TestResources/deploy-test-resources.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ parameters:
44
DeleteAfterHours: 8
55
Location: ''
66
EnvVars: {}
7-
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
7+
SubscriptionConfiguration: '{}'
88
ServiceConnection: not-specified
99
ResourceType: test
10-
UseFederatedAuth: false
10+
UseFederatedAuth: true
11+
PersistOidcToken: false
1112

1213
# SubscriptionConfiguration will be splatted into the parameters of the test
1314
# resources script. It should be JSON in the form:
@@ -35,18 +36,32 @@ parameters:
3536
# }
3637
# }
3738

38-
3939
steps:
4040
- template: /eng/common/pipelines/templates/steps/cache-ps-modules.yml
4141

4242
- template: /eng/common/TestResources/setup-environments.yml
4343

44+
- ${{ if eq(parameters.PersistOidcToken, true) }}:
45+
- task: AzureCLI@2
46+
displayName: Set OIDC token
47+
env:
48+
ARM_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
49+
inputs:
50+
azureSubscription: ${{ parameters.ServiceConnection }}
51+
addSpnToEnvironment: true
52+
scriptLocation: inlineScript
53+
scriptType: pscore
54+
inlineScript: |
55+
Write-Host "##vso[task.setvariable variable=ARM_OIDC_TOKEN;issecret=true]$($env:idToken)"
56+
4457
- ${{ if eq('true', parameters.UseFederatedAuth) }}:
4558
- task: AzurePowerShell@5
46-
displayName: Deploy test resources
59+
displayName: 🚀 Deploy test resources
4760
env:
4861
TEMP: $(Agent.TempDirectory)
4962
PoolSubnet: $(PoolSubnet)
63+
${{ if eq(parameters.PersistOidcToken, true) }}:
64+
ARM_OIDC_TOKEN: $(ARM_OIDC_TOKEN)
5065
${{ insert }}: ${{ parameters.EnvVars }}
5166
inputs:
5267
azureSubscription: ${{ parameters.ServiceConnection }}
@@ -59,6 +74,21 @@ steps:
5974
${{ parameters.SubscriptionConfiguration }}
6075
'@ | ConvertFrom-Json -AsHashtable;
6176
77+
$context = Get-AzContext
78+
$subscriptionConfiguration["Environment"] = $context.Environment.Name
79+
$subscriptionConfiguration["SubscriptionId"] = $context.Subscription.Id
80+
$subscriptionConfiguration["TenantId"] = $context.Subscription.TenantId
81+
$subscriptionConfiguration["TestApplicationId"] = $context.Account.Id
82+
$subscriptionConfiguration["ProvisionerApplicationId"] = $context.Account.Id
83+
84+
$principal = Get-AzADServicePrincipal -ApplicationId $context.Account.Id
85+
$subscriptionConfiguration["TestApplicationOid"] = $principal.Id
86+
$subscriptionConfiguration["ProvisionerApplicationOid"] = $principal.Id
87+
88+
Write-Host ($subscriptionConfiguration | ConvertTo-Json)
89+
# Write the new SubscriptionConfiguration to be used by the remove test resources
90+
Write-Host "##vso[task.setvariable variable=SubscriptionConfiguration;]$($subscriptionConfiguration | ConvertTo-Json -Compress)"
91+
6292
# The subscriptionConfiguration may have ArmTemplateParameters defined, so
6393
# pass those in via the ArmTemplateParameters flag, and handle any
6494
# additional parameters from the pipelines via AdditionalParameters
@@ -96,7 +126,7 @@ steps:
96126
-ServicePrincipalAuth `
97127
-Force `
98128
-Verbose | Out-Null
99-
displayName: Deploy test resources
129+
displayName: 🚀 Deploy test resources
100130
env:
101131
TEMP: $(Agent.TempDirectory)
102132
PoolSubnet: $(PoolSubnet)

eng/common/TestResources/remove-test-resources.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
parameters:
55
ServiceDirectory: ''
6-
SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources)
6+
SubscriptionConfiguration: $(SubscriptionConfiguration)
77
ServiceConnection: not-specified
88
ResourceType: test
99
EnvVars: {}
10-
UseFederatedAuth: false
10+
UseFederatedAuth: true
1111

1212
# SubscriptionConfiguration will be splat into the parameters of the test
1313
# resources script. It should be JSON in the form:

eng/common/TestResources/sub-config/AzureChinaMsft.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

eng/common/TestResources/sub-config/AzurePreviewMsft.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

eng/common/TestResources/sub-config/AzurePublicMsft.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

eng/common/TestResources/sub-config/AzureUsGovMsft.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

eng/common/pipelines/codeowners-linter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ stages:
3131
vmImage: ubuntu-22.04
3232

3333
variables:
34-
CodeownersLinterVersion: '1.0.0-dev.20240614.4'
34+
CodeownersLinterVersion: '1.0.0-dev.20240926.2'
3535
DotNetDevOpsFeed: "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-for-net/nuget/v3/index.json"
3636
RepoLabelUri: "https://azuresdkartifacts.blob.core.windows.net/azure-sdk-write-teams/repository-labels-blob"
3737
TeamUserUri: "https://azuresdkartifacts.blob.core.windows.net/azure-sdk-write-teams/azure-sdk-write-teams-blob"

0 commit comments

Comments
 (0)