Azure DevOps

이 가이드에서는 자동화된 성능 테스트를 위해 LoadFocus JMeter API Client를 Azure DevOps와 통합하는 방법을 설명합니다.

설정 단계

1. Azure Key Vault에 자격 증명 저장

안전한 자격 증명 관리를 위해 LoadFocus API 자격 증명을 Azure Key Vault에 저장합니다:

  1. Azure에 Key Vault가 없다면 생성합니다
  2. 다음 시크릿을 추가합니다:
    • loadfocus-api-key: LoadFocus API 키
    • loadfocus-team-id: LoadFocus 팀 ID
  3. 파이프라인에서 Key Vault에 접근하기 위한 서비스 연결을 설정합니다

2. Azure Pipeline 생성

리포지토리에 azure-pipelines.yml이라는 새 파일을 생성합니다:

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. Key Vault 통합으로 변수 그룹 설정

  1. Go to Pipelines > Library > Variable Groups
  2. Create a new Variable Group named "loadfocus-variables"
  3. Link it to your Azure Key Vault
  4. Add the following variables, linking them to your Key Vault secrets:
    • LOADFOCUS_API_KEY: Link to loadfocus-api-key secret
    • LOADFOCUS_TEAM_ID: Link to loadfocus-team-id secret

고급 구성

YAML 템플릿 사용

재사용 가능한 성능 테스트 단계를 위해 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

그런 다음 메인 파이프라인에서:

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

여러 테스트 실행

여러 성능 테스트를 순차적으로 실행하려면:

- 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'

Azure Test Plans와의 통합

성능 테스트 결과를 Azure Test Plans와 통합하려면:

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

JSON 출력을 JUnit 형식으로 변환해야 합니다:

- 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'

Azure DevOps 통합 팁

  1. Parallel Jobs: If you have multiple performance tests, consider using parallel jobs:

    jobs:
    - job: API_Performance_Test
    steps:
    # Run API performance test
    - job: UI_Performance_Test
    steps:
    # Run UI performance test
  2. Deployment Gates: Use performance test results as a deployment gate:

    - job: DeploymentGate
    steps:
    - script: |
    # Check if performance tests passed
    if grep -q '"overallResult": "FAILED"' $(Build.ArtifactStagingDirectory)/performance_results.json; then
    echo "##vso[task.logissue type=error]Performance tests failed"
    echo "##vso[task.complete result=Failed;]"
    fi
  3. Custom Dashboard: Create a custom dashboard to visualize performance test results over time.

  4. Notifications: Set up notifications for performance test failures:

    - task: SendEmail@1
    inputs:
    to: 'team@example.com'
    subject: 'Performance Test Failed'
    body: 'Performance tests failed to meet thresholds. See attached results.'
    addAttachment: true
    attachmentPath: '$(Build.ArtifactStagingDirectory)/performance_results.json'
    condition: failed()

자세한 내용은 Azure DevOps 문서LoadFocus API Client 문서를 참조하세요.