Azure DevOps

Deze handleiding legt uit hoe u de LoadFocus JMeter API Client integreert met Azure DevOps voor geautomatiseerde prestatietests.

Installatiestappen

1. Referenties Opslaan in Azure Key Vault

Voor veilig referentiebeheer slaat u uw LoadFocus API-referenties op in Azure Key Vault:

  1. Maak een Key Vault in Azure aan als u er nog geen heeft
  2. Voeg de volgende secrets toe:
    • loadfocus-api-key: Uw LoadFocus API-sleutel
    • loadfocus-team-id: Uw LoadFocus team-ID
  3. Stel een serviceverbinding in om de Key Vault vanuit uw pipeline te benaderen

2. Een Azure Pipeline Aanmaken

Maak een nieuw bestand genaamd azure-pipelines.yml in uw repository:

trigger:
- main
- develop
pool:
vmImage: 'ubuntu-latest'
variables:
- group: loadfocus-variables # Variable group containing Key Vault references
stages:
- stage: Build
jobs:
- job: BuildAndTest
steps:
# Your existing build and test steps...
- stage: PerformanceTest
dependsOn: Build
condition: succeeded()
jobs:
- job: RunPerformanceTests
steps:
- task: NodeTool@0
inputs:
versionSpec: '16.x'
displayName: 'Install Node.js'
- script: |
npm install -g @loadfocus/loadfocus-api-client
displayName: 'Install LoadFocus JMeter API Client'
- script: |
loadfocus-api config set apikey $(LOADFOCUS_API_KEY)
loadfocus-api config set teamid $(LOADFOCUS_TEAM_ID)
displayName: 'Configure LoadFocus API Client'
- script: |
loadfocus-api jmeter run-test \
--name "AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)" \
--thresholds "avgresponse<=200,errors==0,p95<=250" \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
displayName: 'Run Performance Tests'
continueOnError: false
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'performance-test-results'
displayName: 'Publish Performance Test Results'
- stage: Deploy
dependsOn: PerformanceTest
condition: succeeded()
jobs:
- job: DeployApplication
steps:
# Your deployment steps...

3. Variable Group Instellen met Key Vault Integratie

  1. Ga naar Pipelines > Library > Variable Groups
  2. Maak een nieuwe Variable Group genaamd "loadfocus-variables"
  3. Koppel deze aan uw Azure Key Vault
  4. Voeg de volgende variabelen toe, gekoppeld aan uw Key Vault secrets:
    • LOADFOCUS_API_KEY: Koppel aan loadfocus-api-key secret
    • LOADFOCUS_TEAM_ID: Koppel aan loadfocus-team-id secret

Geavanceerde Configuratie

YAML Templates Gebruiken

Maak voor herbruikbare prestatietest-stappen een templatebestand performance-test-template.yml:

parameters:
testName: 'Default_Test'
thresholds: 'avgresponse<=200,errors==0,p95<=250'
waitTimeout: 1800
steps:
- script: |
loadfocus-api jmeter run-test \
--name "${{ parameters.testName }}" \
--thresholds "${{ parameters.thresholds }}" \
--waitTimeout ${{ parameters.waitTimeout }} \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
displayName: 'Run Performance Tests'
continueOnError: false

Vervolgens in uw hoofdpipeline:

- template: performance-test-template.yml
parameters:
testName: 'AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)'
thresholds: 'avgresponse<=150,errors==0,p95<=200'
waitTimeout: 2400

Meerdere Tests Uitvoeren

Om meerdere prestatietests achtereenvolgens uit te voeren:

- script: |
# Run API test
loadfocus-api jmeter run-test \
--name "API_Test" \
--thresholds "avgresponse<=200,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/api_test_results.json
# Run UI test
loadfocus-api jmeter run-test \
--name "UI_Test" \
--thresholds "avgresponse<=500,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/ui_test_results.json
displayName: 'Run Multiple Performance Tests'

Integratie met Azure Test Plans

Om prestatietestresultaten te integreren met Azure Test Plans:

- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '$(Build.ArtifactStagingDirectory)/test-results.xml'
testRunTitle: 'Performance Tests'
displayName: 'Publish Test Results'
condition: succeededOrFailed()

U moet de JSON-uitvoer converteren naar JUnit-formaat:

- script: |
# Run performance test
loadfocus-api jmeter run-test \
--name "AzureDevOps_Test" \
--thresholds "avgresponse<=200,errors==0" \
--format json > $(Build.ArtifactStagingDirectory)/performance_results.json
# Convert JSON to JUnit format (using a custom script)
node convert-to-junit.js \
$(Build.ArtifactStagingDirectory)/performance_results.json \
$(Build.ArtifactStagingDirectory)/test-results.xml
displayName: 'Run Performance Tests and Convert Results'

Tips voor Azure DevOps Integratie

  1. Parallelle Jobs: Als u meerdere prestatietests heeft, overweeg dan parallelle jobs te gebruiken.

  2. Deployment Gates: Gebruik prestatietestresultaten als deployment gate.

  3. Aangepast Dashboard: Maak een aangepast dashboard om prestatietestresultaten in de loop der tijd te visualiseren.

  4. Meldingen: Stel meldingen in voor mislukte prestatietests.

Voor meer informatie, raadpleeg de Azure DevOps documentatie en de LoadFocus API Client documentatie.