Azure DevOpsインテグレーション
このガイドでは、LoadFocus JMeter APIクライアントをAzure DevOpsと統合して自動パフォーマンステストを実現する方法を説明します。
セットアップ手順
1. Azure Key Vaultに資格情報を保存する
安全な資格情報管理のために、LoadFocus APIの資格情報をAzure Key Vaultに保存します:
- Create a Key Vault in Azure if you don't have one
- Add the following secrets:
loadfocus-api-key: Your LoadFocus API keyloadfocus-team-id: Your LoadFocus team ID
- Set up a service connection to access the Key Vault from your pipeline
2. Azure Pipelineを作成する
リポジトリにazure-pipelines.ymlという名前の新しいファイルを作成します:
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. Key Vault統合で変数グループをセットアップする
- Go to Pipelines > Library > Variable Groups
- Create a new Variable Group named "loadfocus-variables"
- Link it to your Azure Key Vault
- Add the following variables, linking them to your Key Vault secrets:
LOADFOCUS_API_KEY: Link toloadfocus-api-keysecretLOADFOCUS_TEAM_ID: Link toloadfocus-team-idsecret
高度な設定
YAMLテンプレートの使用
再利用可能なパフォーマンステスト手順のために、テンプレートファイル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
次にメインパイプラインで:
- template: performance-test-template.ymlparameters:testName: 'AzureDevOps_$(Build.Repository.Name)_$(Build.SourceBranchName)'thresholds: 'avgresponse<=150,errors==0,p95<=200'waitTimeout: 2400
複数テストの実行
複数のパフォーマンステストを順番に実行するには:
- 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'
Azure Test Plansとの統合
パフォーマンステスト結果をAzure Test Plansと統合するには:
- task: PublishTestResults@2inputs:testResultsFormat: 'JUnit'testResultsFiles: '$(Build.ArtifactStagingDirectory)/test-results.xml'testRunTitle: 'Performance Tests'displayName: 'Publish Test Results'condition: succeededOrFailed()
JSON出力を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'
Azure DevOpsインテグレーションのヒント
Parallel Jobs: If you have multiple performance tests, consider using parallel jobs:
jobs:- job: API_Performance_Teststeps:# Run API performance test- job: UI_Performance_Teststeps:# Run UI performance testDeployment Gates: Use performance test results as a deployment gate:
- 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;]"fiCustom Dashboard: Create a custom dashboard to visualize performance test results over time.
Notifications: Set up notifications for performance test failures:
- 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()
詳細については、Azure DevOpsドキュメントおよびLoadFocus APIクライアントドキュメントをご参照ください。