Azure DevOps
คู่มือนี้อธิบายวิธีผสาน LoadFocus JMeter API Client กับ Azure DevOps สำหรับการทดสอบประสิทธิภาพอัตโนมัติ
ขั้นตอนการตั้งค่า
1. จัดเก็บ Credentials ใน Azure Key Vault
สำหรับการจัดการ credentials อย่างปลอดภัย จัดเก็บ LoadFocus API credentials ใน Azure Key Vault:
- สร้าง Key Vault ใน Azure หากยังไม่มี
- เพิ่ม secrets ต่อไปนี้:
loadfocus-api-key: API key ของ LoadFocusloadfocus-team-id: Team ID ของ LoadFocus
- ตั้งค่า service connection เพื่อเข้าถึง Key Vault จาก pipeline
2. สร้าง Azure Pipeline
สร้างไฟล์ใหม่ชื่อ azure-pipelines.yml ใน 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. ตั้งค่า Variable Group พร้อมการผสาน Key Vault
- ไปที่ Pipelines > Library > Variable Groups
- สร้าง Variable Group ใหม่ชื่อ "loadfocus-variables"
- เชื่อมโยงกับ Azure Key Vault
- เพิ่ม variables ต่อไปนี้ เชื่อมโยงกับ Key Vault secrets:
LOADFOCUS_API_KEY: เชื่อมโยงกับ secretloadfocus-api-keyLOADFOCUS_TEAM_ID: เชื่อมโยงกับ secretloadfocus-team-id
การกำหนดค่าขั้นสูง
การใช้ YAML Templates
สำหรับขั้นตอนทดสอบประสิทธิภาพที่ใช้ซ้ำได้ สร้างไฟล์ 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
จากนั้นใน pipeline หลักของคุณ:
- 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 DevOps
- Parallel Jobs: หากมีทดสอบประสิทธิภาพหลายรายการ พิจารณาใช้ parallel jobs
- Deployment Gates: ใช้ผลทดสอบประสิทธิภาพเป็น deployment gate
- Custom Dashboard: สร้าง custom dashboard เพื่อแสดงผลทดสอบประสิทธิภาพเมื่อเวลาผ่านไป
- Notifications: ตั้งค่าการแจ้งเตือนสำหรับความล้มเหลวของทดสอบประสิทธิภาพ
สำหรับข้อมูลเพิ่มเติม ดู เอกสาร Azure DevOps และ เอกสาร LoadFocus API Client