diff --git a/eng/common/TestResources/New-TestResources.ps1 b/eng/common/TestResources/New-TestResources.ps1 index 25f0b18c31cf..eccb761a7c5e 100644 --- a/eng/common/TestResources/New-TestResources.ps1 +++ b/eng/common/TestResources/New-TestResources.ps1 @@ -21,6 +21,9 @@ param ( [Parameter(Mandatory = $true, Position = 0)] [string] $ServiceDirectory, + [Parameter()] + [string] $Artifacts, + [Parameter()] [ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')] [string] $TestApplicationId, @@ -144,16 +147,30 @@ try { # Azure SDK Developer Playground $defaultSubscription = "faa080af-c1d8-40ad-9cce-e1a450ca5b57" - Write-Verbose "Checking for '$templateFileName' files under '$root'" - Get-ChildItem -Path $root -Filter $templateFileName -Recurse | ForEach-Object { - $templateFile = $_.FullName + # Deploy test resources according to Artifacts + if ($Artifacts) { + $Artifacts.TrimStart(",").Split(",") | ForEach-Object { + $templateFilePath = Join-Path $root $_ + Write-Verbose "Checking for '$templateFileName' files under '$templateFilePath'" + Get-ChildItem -Path $templateFilePath -Filter $templateFileName -Recurse | ForEach-Object { + $templateFile = $_.FullName + + Write-Verbose "Found template '$templateFile'" + $templateFiles += $templateFile + } + } + } else { + Write-Verbose "Checking for '$templateFileName' files under '$root'" + Get-ChildItem -Path $root -Filter $templateFileName -Recurse | ForEach-Object { + $templateFile = $_.FullName - Write-Verbose "Found template '$templateFile'" - $templateFiles += $templateFile + Write-Verbose "Found template '$templateFile'" + $templateFiles += $templateFile + } } if (!$templateFiles) { - Write-Warning -Message "No template files found under '$root'" + Write-Warning -Message "No template files found" exit } @@ -550,6 +567,11 @@ A directory under 'sdk' in the repository root - optionally with subdirectories specified - in which to discover ARM templates named 'test-resources.json'. This can also be an absolute path or specify parent directories. +.PARAMETER Artifacts +A string of all artifact names defined in tests.yml under ServiceDirectory. If the +value is not set, then all ARM templates under ServiceDirectory will be found to deploy +test resources. Otherwise, only templates under ServiceDirectory/artifact will be discovered. + .PARAMETER TestApplicationId The AAD Application ID to authenticate the test runner against deployed resources. Passed to the ARM template as 'testApplicationId'. diff --git a/eng/common/TestResources/New-TestResources.ps1.md b/eng/common/TestResources/New-TestResources.ps1.md index 096c7e70aa37..b518eec4045d 100644 --- a/eng/common/TestResources/New-TestResources.ps1.md +++ b/eng/common/TestResources/New-TestResources.ps1.md @@ -15,7 +15,7 @@ Deploys live test resources defined for a service directory to Azure. ### Default (Default) ``` New-TestResources.ps1 [-BaseName ] [-ResourceGroupName ] [-ServiceDirectory] - [-TestApplicationId ] [-TestApplicationSecret ] [-TestApplicationOid ] + [-Artifacts ] [-TestApplicationId ] [-TestApplicationSecret ] [-TestApplicationOid ] [-DeleteAfterHours ] [-Location ] [-Environment ] [-ArmTemplateParameters ] [-AdditionalParameters ] [-EnvironmentVariables ] [-CI] [-Force] [-OutFile] [-WhatIf] [-Confirm] [] @@ -35,8 +35,9 @@ New-TestResources.ps1 [-BaseName ] [-ResourceGroupName ] [-Servi Deploys live test resouces specified in test-resources.json files to a resource group. -This script searches the directory specified in $ServiceDirectory recursively -for files named test-resources.json. +This script searches for files named test-resources.json in each artifact project +of $Artifacts under $ServiceDirectory recursively. When $Artifacts is not set, the +script will search the directory $ServiceDirectory directly. All found test-resources.json files will be deployed to the test resource group. @@ -70,6 +71,7 @@ the SecureString to plaintext by another means. New-TestResources.ps1 ` -BaseName 'Generated' ` -ServiceDirectory '$(ServiceDirectory)' ` + -Artifacts '$(Artifacts)' ` -TenantId '$(TenantId)' ` -ProvisionerApplicationId '$(ProvisionerId)' ` -ProvisionerApplicationSecret '$(ProvisionerSecret)' ` @@ -142,6 +144,23 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Artifacts +A string of all artifact names defined in tests.yml under ServiceDirectory. If the +value is not set, then all ARM templates under ServiceDirectory will be found to deploy +test resources. Otherwise, only templates under ServiceDirectory/artifact will be discovered. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -TestApplicationId The AAD Application ID to authenticate the test runner against deployed resources. diff --git a/eng/common/TestResources/deploy-test-resources.yml b/eng/common/TestResources/deploy-test-resources.yml index a9d693b99420..47ed2b8c3bd7 100644 --- a/eng/common/TestResources/deploy-test-resources.yml +++ b/eng/common/TestResources/deploy-test-resources.yml @@ -4,7 +4,7 @@ parameters: DeleteAfterHours: 8 Location: '' SubscriptionConfiguration: $(sub-config-azure-cloud-test-resources) - + Artifacts: [] # SubscriptionConfiguration will be splatted into the parameters of the test # resources script. It should be JSON in the form: # { @@ -35,6 +35,15 @@ parameters: steps: - template: /eng/common/TestResources/setup-az-modules.yml + - pwsh: | + Write-Host "##vso[task.setvariable variable=ArtifactList;]" + displayName: Initialize artifact list variable + + - ${{each artifact in parameters.Artifacts }}: + - pwsh: | + Write-Host "##vso[task.setvariable variable=ArtifactList;]$(ArtifactList),${{artifact.name}}" + displayName: Append ${{artifact.name}} to artifact list + - pwsh: | eng/common/TestResources/Import-AzModules.ps1 @@ -48,6 +57,7 @@ steps: eng/common/TestResources/New-TestResources.ps1 ` -BaseName 'Generated' ` -ServiceDirectory '${{ parameters.ServiceDirectory }}' ` + -Artifacts '$(ArtifactList)' ` -Location '${{ parameters.Location }}' ` -DeleteAfterHours '${{ parameters.DeleteAfterHours }}' ` @subscriptionConfiguration ` diff --git a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml index 0701d25597aa..0c106d57c6b6 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml @@ -102,6 +102,7 @@ jobs: SubscriptionConfiguration: $(SubscriptionConfiguration) ArmTemplateParameters: $(ArmTemplateParameters) Location: $(Location) + Artifacts: ${{ parameters.Artifacts }} - ${{ parameters.PreRunSteps }} @@ -109,7 +110,7 @@ jobs: parameters: Artifacts: ${{parameters.Artifacts}} AdditionalModules: ${{parameters.AdditionalModules}} - + - task: UsePythonVersion@0 displayName: 'Use Python 3.6' inputs: