Integrazione Azure DevOps
Questa guida spiega come integrare il Client API JMeter di LoadFocus con Azure DevOps per test di prestazione automatizzati.
Passaggi di Configurazione
1. Memorizzare le Credenziali in Azure Key Vault
Per una gestione sicura delle credenziali, memorizzate le vostre credenziali API LoadFocus in Azure Key Vault:
- Create un Key Vault in Azure se non ne avete uno
- Aggiungete i seguenti segreti:
loadfocus-api-key: La vostra chiave API LoadFocusloadfocus-team-id: Il vostro ID team LoadFocus
- Configurate una connessione di servizio per accedere al Key Vault dalla vostra pipeline
2. Creare una Pipeline Azure
Create un nuovo file chiamato azure-pipelines.yml nel vostro repository:
trigger:- main- developpool:vmImage: 'ubuntu-latest'variables:- group: loadfocus-variables # Variable group containing Key Vault referencesstages:- stage: Buildjobs:- job: BuildAndTeststeps:# Your existing build and test steps...- stage: PerformanceTestdependsOn: Buildcondition: succeeded()jobs:- job: RunPerformanceTestssteps:- task: NodeTool@0inputs:versionSpec: '16.x'displayName: 'Install Node.js'- script: |npm install -g @loadfocus/loadfocus-api-clientdisplayName: '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.jsondisplayName: 'Run Performance Tests'continueOnError: false- task: PublishBuildArtifacts@1inputs:pathtoPublish: '$(Build.ArtifactStagingDirectory)'artifactName: 'performance-test-results'displayName: 'Publish Performance Test Results'- stage: DeploydependsOn: PerformanceTestcondition: succeeded()jobs:- job: DeployApplicationsteps:# Your deployment steps...
3. Configurare il Variable Group con l'Integrazione Key Vault
- Andate su Pipelines > Library > Variable Groups
- Create un nuovo Variable Group chiamato "loadfocus-variables"
- Collegatelo al vostro Azure Key Vault
- Aggiungete le seguenti variabili, collegandole ai vostri segreti del Key Vault:
LOADFOCUS_API_KEY: Collegato al segretoloadfocus-api-keyLOADFOCUS_TEAM_ID: Collegato al segretoloadfocus-team-id
Configurazione Avanzata
Utilizzo di Template YAML
Per passaggi riutilizzabili di test di prestazione, create un file template performance-test-template.yml:
parameters:testName: 'Default_Test'thresholds: 'avgresponse<=200,errors==0,p95<=250'waitTimeout: 1800steps:- script: |loadfocus-api jmeter run-test \--name "${{ parameters.testName }}" \--thresholds "${{ parameters.thresholds }}" \--waitTimeout ${{ parameters.waitTimeout }} \--format json > $(Build.ArtifactStagingDirectory)/performance_results.jsondisplayName: 'Run Performance Tests'continueOnError: false
Poi nella vostra pipeline principale:
- template: performance-test-template.ymlparameters:testName: 'AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)'thresholds: 'avgresponse<=150,errors==0,p95<=200'waitTimeout: 2400
Esecuzione di Test Multipli
Per eseguire piu test di prestazione in sequenza:
- script: |# Run API testloadfocus-api jmeter run-test \--name "API_Test" \--thresholds "avgresponse<=200,errors==0" \--format json > $(Build.ArtifactStagingDirectory)/api_test_results.json# Run UI testloadfocus-api jmeter run-test \--name "UI_Test" \--thresholds "avgresponse<=500,errors==0" \--format json > $(Build.ArtifactStagingDirectory)/ui_test_results.jsondisplayName: 'Run Multiple Performance Tests'
Integrazione con Azure Test Plans
Per integrare i risultati dei test di prestazione con Azure Test Plans:
- task: PublishTestResults@2inputs:testResultsFormat: 'JUnit'testResultsFiles: '$(Build.ArtifactStagingDirectory)/test-results.xml'testRunTitle: 'Performance Tests'displayName: 'Publish Test Results'condition: succeededOrFailed()
Dovrete convertire l'output JSON nel formato JUnit:
- script: |# Run performance testloadfocus-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.xmldisplayName: 'Run Performance Tests and Convert Results'
Suggerimenti per l'Integrazione con Azure DevOps
Job Paralleli: Se avete piu test di prestazione, considerate l'utilizzo di job paralleli:
jobs:- job: API_Performance_Teststeps:# Run API performance test- job: UI_Performance_Teststeps:# Run UI performance testGate di Deploy: Utilizzate i risultati dei test di prestazione come gate di deploy:
- job: DeploymentGatesteps:- script: |# Check if performance tests passedif grep -q '"overallResult": "FAILED"' $(Build.ArtifactStagingDirectory)/performance_results.json; thenecho "##vso[task.logissue type=error]Performance tests failed"echo "##vso[task.complete result=Failed;]"fiDashboard Personalizzata: Create una dashboard personalizzata per visualizzare i risultati dei test di prestazione nel tempo.
Notifiche: Configurate le notifiche per i fallimenti dei test di prestazione:
- task: SendEmail@1inputs:to: 'team@example.com'subject: 'Performance Test Failed'body: 'Performance tests failed to meet thresholds. See attached results.'addAttachment: trueattachmentPath: '$(Build.ArtifactStagingDirectory)/performance_results.json'condition: failed()
Per maggiori informazioni, consultate la documentazione di Azure DevOps e la documentazione del Client API LoadFocus.