@@ -42,6 +42,12 @@ parameters:
4242- name : OSName
4343 type : string
4444 default : ' '
45+ - name : EnvVars
46+ type : object
47+ default : {}
48+ - name : UseFederatedAuth
49+ type : boolean
50+ default : false
4551
4652jobs :
4753- job :
@@ -156,6 +162,9 @@ jobs:
156162 SubscriptionConfigurations : ${{ parameters.CloudConfig.SubscriptionConfigurations }}
157163 EnvVars :
158164 Pool : $(Pool)
165+ ${{ insert }} : ${{ parameters.EnvVars }}
166+ ${{ if parameters.UseFederatedAuth }} :
167+ SubscriptionConfigurationFilePaths : ${{ parameters.CloudConfig.SubscriptionConfigurationFilePaths }}
159168
160169 - template : /eng/common/TestResources/deploy-test-resources.yml
161170 parameters :
@@ -164,32 +173,56 @@ jobs:
164173 SubscriptionConfiguration : $(SubscriptionConfiguration)
165174 EnvVars :
166175 Pool : $(Pool)
176+ ${{ insert }} : ${{ parameters.EnvVars }}
177+ UseFederatedAuth : ${{ parameters.UseFederatedAuth }}
178+ ServiceConnection : ${{ parameters.CloudConfig.ServiceConnection }}
167179
168180 - template : /eng/common/testproxy/test-proxy-tool.yml
169181 parameters :
170182 runProxy : false
171183
172184 - ${{ parameters.PreTestSteps }}
173185
174- # For non multi-config generator use the same build configuration to run tests
175- # We don't need to set it to invoke ctest
176- # Visual Studio generator used in CI is a multi-config generator.
177- # As such, it requires the configuration argument for building and invoking ctest
178- - bash : |
179- export AZURE_CLIENT_ID=$(${{parameters.ServiceDirectory}}_CLIENT_ID)
180- export AZURE_TENANT_ID=$(${{parameters.ServiceDirectory}}_TENANT_ID)
181- export AZURE_CLIENT_SECRET=$(${{parameters.ServiceDirectory}}_CLIENT_SECRET)
186+ - ${{ if parameters.UseFederatedAuth }} :
187+ - task : AzurePowerShell@5
188+ displayName : ctest
189+ condition : and(succeeded(), ne(variables['RunSamples'], '1'))
190+ inputs :
191+ azureSubscription : ${{ parameters.CloudConfig.ServiceConnection }}
192+ azurePowerShellVersion : LatestVersion
193+ ScriptType : InlineScript
194+ Inline : |
195+ $account = (Get-AzContext).Account
196+ $env:AZURESUBSCRIPTION_CLIENT_ID = $account.Id
197+ $env:AZURESUBSCRIPTION_TENANT_ID = $account.Tenants
182198
183- ctest $(WindowsCtestConfig) -V --tests-regex "${{ parameters.CtestRegex }}" --no-compress-output -T Test
184- workingDirectory: build
185- displayName: ctest
186- # Runs only if test-resources are happily deployed.
187- # unit-tests runs for those configs where samples are not ran.
188- # This enables to run tests and samples at the same time as different matrix configuration.
189- # Then unit-tests runs, samples should not run.
190- condition: and(
191- succeeded(),
192- ne(variables['RunSamples'], '1'))
199+ ctest $(WindowsCtestConfig) -V --tests-regex "${{ parameters.CtestRegex }}" --no-compress-output -T Test
200+ exit $LASTEXITCODE
201+ workingDirectory : build
202+ env :
203+ SYSTEM_ACCESSTOKEN : $(System.AccessToken)
204+ ${{ insert }} : ${{ parameters.EnvVars }}
205+
206+ - ${{ else }} :
207+ # For non multi-config generator use the same build configuration to run tests
208+ # We don't need to set it to invoke ctest
209+ # Visual Studio generator used in CI is a multi-config generator.
210+ # As such, it requires the configuration argument for building and invoking ctest
211+ - bash : |
212+ export AZURE_CLIENT_ID=$(${{parameters.ServiceDirectory}}_CLIENT_ID)
213+ export AZURE_TENANT_ID=$(${{parameters.ServiceDirectory}}_TENANT_ID)
214+ export AZURE_CLIENT_SECRET=$(${{parameters.ServiceDirectory}}_CLIENT_SECRET)
215+
216+ ctest $(WindowsCtestConfig) -V --tests-regex "${{ parameters.CtestRegex }}" --no-compress-output -T Test
217+ workingDirectory: build
218+ displayName: ctest
219+ # Runs only if test-resources are happily deployed.
220+ # unit-tests runs for those configs where samples are not ran.
221+ # This enables to run tests and samples at the same time as different matrix configuration.
222+ # Then unit-tests runs, samples should not run.
223+ condition: and(succeeded(), ne(variables['RunSamples'], '1'))
224+ env:
225+ ${{ insert }}: ${{ parameters.EnvVars }}
193226
194227 - ${{ parameters.PostTestSteps }}
195228
@@ -205,32 +238,66 @@ jobs:
205238 # this step only makes sense when ctest has run
206239 condition : and(succeededOrFailed(), ne(variables['RunSamples'], '1'))
207240
208- # Running Samples step.
209- # Will run samples described on a file name [service]-samples.txt within the build directory.
210- # For example keyvault-samples.txt.
211- # The file is written by CMake during configuration when building samples.
212- - bash : |
213- IFS=$'\n'
214- if [[ -f "./${{ parameters.ServiceDirectory }}-samples.txt" ]]; then
215- for sample in `cat ./${{ parameters.ServiceDirectory }}-samples.txt`
216- do
217- export AZURE_CLIENT_ID=$(${{parameters.ServiceDirectory}}_CLIENT_ID)
218- export AZURE_TENANT_ID=$(${{parameters.ServiceDirectory}}_TENANT_ID)
219- export AZURE_CLIENT_SECRET=$(${{parameters.ServiceDirectory}}_CLIENT_SECRET)
220- echo "**********Running sample: ${sample}"
221- bash -c "$sample"
222- status=$?
223- if [[ $status -eq 0 ]]; then
224- echo "*********Sample completed*********"
225- else
226- echo "*Sample returned a failed code: $status"
227- exit 1
228- fi
229- done
230- fi
231- workingDirectory: build
232- displayName: "Run Samples for : ${{ parameters.ServiceDirectory }}"
233- condition: and(succeeded(), eq(variables['RunSamples'], '1'))
241+
242+ - ${{ if parameters.UseFederatedAuth }} :
243+ # Running Samples step.
244+ # Will run samples described on a file name [service]-samples.txt within the build directory.
245+ # For example keyvault-samples.txt.
246+ # The file is written by CMake during configuration when building samples.
247+ - bash : |
248+ IFS=$'\n'
249+ if [[ -f "./${{ parameters.ServiceDirectory }}-samples.txt" ]]; then
250+ for sample in `cat ./${{ parameters.ServiceDirectory }}-samples.txt`
251+ do
252+ export AZURE_CLIENT_ID=$(${{parameters.ServiceDirectory}}_CLIENT_ID)
253+ export AZURE_TENANT_ID=$(${{parameters.ServiceDirectory}}_TENANT_ID)
254+ export AZURE_CLIENT_SECRET=$(${{parameters.ServiceDirectory}}_CLIENT_SECRET)
255+ echo "**********Running sample: ${sample}"
256+ bash -c "$sample"
257+ status=$?
258+ if [[ $status -eq 0 ]]; then
259+ echo "*********Sample completed*********"
260+ else
261+ echo "*Sample returned a failed code: $status"
262+ exit 1
263+ fi
264+ done
265+ fi
266+ workingDirectory: build
267+ displayName: "Run Samples for : ${{ parameters.ServiceDirectory }}"
268+ condition: and(succeeded(), eq(variables['RunSamples'], '1'))
269+ env:
270+ ${{ insert }}: ${{ parameters.EnvVars }}
271+
272+ - ${{ else }} :
273+ - task : AzurePowerShell@5
274+ displayName : " Run Samples for : ${{ parameters.ServiceDirectory }}"
275+ condition : and(succeeded(), eq(variables['RunSamples'], '1'))
276+ inputs :
277+ azureSubscription : ${{ parameters.CloudConfig.ServiceConnection }}
278+ azurePowerShellVersion : LatestVersion
279+ ScriptType : InlineScript
280+ Inline : |
281+ $account = (Get-AzContext).Account
282+ $env:AZURESUBSCRIPTION_CLIENT_ID = $account.Id
283+ $env:AZURESUBSCRIPTION_TENANT_ID = $account.Tenants
284+
285+ if (Test-Path -Path "${{ parameters.ServiceDirectory }}-samples.txt") {
286+ $samples = Get-Content "${{ parameters.ServiceDirectory }}-samples.txt"
287+ foreach ($sample in $samples) {
288+ Write-Host "**********Running sample: $sample"
289+ & "$sample"
290+ if ($LASTEXITCODE) {
291+ Write-Host "Sample failed with exit code $LASTEXITCODE"
292+ exit 1
293+ }
294+ Write-Host "**********Sample completed"
295+ }
296+ }
297+ workingDirectory : build
298+ env :
299+ SYSTEM_ACCESSTOKEN : $(System.AccessToken)
300+ ${{ insert }} : ${{ parameters.EnvVars }}
234301
235302 # Make coverage targets (specified in coverage_targets.txt) and assemble
236303 # coverage report
@@ -252,3 +319,6 @@ jobs:
252319 parameters :
253320 ServiceDirectory : ${{ parameters.ServiceDirectory }}
254321 SubscriptionConfiguration : $(SubscriptionConfiguration)
322+ UseFederatedAuth : ${{ parameters.UseFederatedAuth }}
323+ EnvVars : ${{ parameters.EnvVars }}
324+ ServiceConnection : ${{ parameters.CloudConfig.ServiceConnection }}
0 commit comments