Azure DevOps

Ez az útmutató bemutatja, hogyan integrálhatja a LoadFocus JMeter API klienst az Azure DevOps-szal az automatizált teljesítményteszteléshez.

Beállítási lépések

1. Hitelesítő adatok tárolása az Azure Key Vaultban

A biztonságos hitelesítő adatok kezeléséhez tárolja LoadFocus API hitelesítő adatait az Azure Key Vaultban:

  1. Hozzon létre egy Key Vaultot az Azure-ban, ha még nincs
  2. Adja hozzá a következő titkos kulcsokat:
    • loadfocus-api-key: Az Ön LoadFocus API kulcsa
    • loadfocus-team-id: Az Ön LoadFocus csapat azonosítója
  3. Állítson be egy szolgáltatás kapcsolatot a Key Vault eléréséhez a pipeline-ból

2. Azure Pipeline létrehozása

Hozzon létre egy új fájlt azure-pipelines.yml néven a tárhelyen:

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. Változócsoport beállítása Key Vault integrációval

  1. Navigáljon a Pipelines > Library > Variable Groups menüpontba
  2. Hozzon létre egy új változócsoportot "loadfocus-variables" néven
  3. Kapcsolja össze az Azure Key Vaulttal
  4. Adja hozzá a következő változókat a Key Vault titkos kulcsaihoz kapcsolva:
    • LOADFOCUS_API_KEY: Kapcsolja a loadfocus-api-key titkos kulcshoz
    • LOADFOCUS_TEAM_ID: Kapcsolja a loadfocus-team-id titkos kulcshoz

Haladó konfiguráció

YAML sablonok használata

Újrafelhasználható teljesítménytesztelési lépésekhez hozzon létre egy performance-test-template.yml sablonfájlt:

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

Ezután a fő pipeline-ban:

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

Több teszt futtatása

Több teljesítményteszt egymás utáni futtatásához:

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

Integráció az Azure Test Plans-szel

A teljesítményteszt eredmények integrálásához az Azure Test Plans-szel:

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

A JSON kimenetet JUnit formátumba kell konvertálnia:

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

Tippek az Azure DevOps integrációhoz

  1. Párhuzamos feladatok: Ha több teljesítménytesztje van, fontolja meg párhuzamos feladatok használatát:

    jobs:
    - job: API_Performance_Test
    steps:
    # Run API performance test
    - job: UI_Performance_Test
    steps:
    # Run UI performance test
  2. Telepítési kapuk: Használja a teljesítményteszt eredményeket telepítési kapuként:

    - 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. Egyéni irányítópult: Hozzon létre egyéni irányítópultot a teljesítményteszt eredmények időbeli megjelenítéséhez.

  4. Értesítések: Állítson be értesítéseket a teljesítményteszt hibákhoz:

    - 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()

További információkért tekintse meg az Azure DevOps dokumentációt és a LoadFocus API kliens dokumentációt.