GitLab CI/CD
Tämä opas selittää kuinka integroida LoadFocus JMeter API Client GitLab CI/CD:n kanssa automatisoitua suorituskykytestausta varten.
Asennusvaiheet
1. Tallenna tunnistetiedot GitLab CI/CD -muuttujina
Tallenna ensin LoadFocus API -tunnistetietosi GitLab CI/CD -muuttujina:
- Siirry GitLab-projektiisi
- Siirry kohtaan Settings > CI/CD > Variables
- Lisää seuraavat muuttujat:
LOADFOCUS_API_KEY: LoadFocus API -avaimesi (merkitse "Masked")LOADFOCUS_TEAM_ID: LoadFocus tiimi-ID:si
2. Luo GitLab CI/CD -putki
Luo tai päivitä .gitlab-ci.yml-tiedostosi repositoriossasi:
stages:- build- test- performance- deployvariables:NODE_VERSION: "16"build:stage: buildimage: node:${NODE_VERSION}script:- npm install- npm run buildartifacts:paths:- dist/expire_in: 1 weektest:stage: testimage: node:${NODE_VERSION}script:- npm install- npm testperformance_test:stage: performanceimage: node:${NODE_VERSION}script:# Install LoadFocus JMeter API Client- npm install -g @loadfocus/loadfocus-api-client# Configure LoadFocus API Client- loadfocus-api config set apikey $LOADFOCUS_API_KEY- loadfocus-api config set teamid $LOADFOCUS_TEAM_ID# Run Performance Tests- |loadfocus-api jmeter run-test \--name "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.jsonartifacts:paths:- performance_results.jsonexpire_in: 1 weekwhen: always# Optional: Only run on specific branchesonly:- main- developdeploy:stage: deployscript:- echo "Deploying application..."only:- main# Only deploy if all previous stages succeededwhen: on_success
Vinkkejä GitLab CI/CD -integraatioon
Välimuisti: Välimuistita npm-riippuvuudet putkiajojen nopeuttamiseksi:
performance_test:stage: performanceimage: node:${NODE_VERSION}cache:key: ${CI_COMMIT_REF_SLUG}paths:- node_modules/script:- npm install -g @loadfocus/loadfocus-api-client# Rest of the script...Aikakatkaisuasetukset: Aseta aikakatkaisut pitkäkestoisille suorituskykytesteille:
performance_test:stage: performanceimage: node:${NODE_VERSION}timeout: 2h # Set a 2-hour timeoutscript:# Performance test script...Manuaaliset laukaisut: Mahdollista suorituskykytestien manuaalinen laukaisu:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:# Performance test script...when: manualDynaaminen testikonfigurointi: Käytä GitLabin ennalta määritettyjä muuttujia testien dynaamiseen konfigurointiin:
performance_test:stage: performanceimage: node:${NODE_VERSION}script:- |# Set thresholds based on branchif [ "$CI_COMMIT_REF_NAME" = "main" ]; thenTHRESHOLDS="avgresponse<=200,errors==0,p95<=250"elseTHRESHOLDS="avgresponse<=300,errors==0,p95<=500"filoadfocus-api jmeter run-test \--name "GitLab_${CI_PROJECT_NAME}_${CI_COMMIT_REF_NAME}" \--thresholds "$THRESHOLDS" \--format json > performance_results.json
Lisätietoja löydät GitLab CI/CD -dokumentaatiosta ja LoadFocus API Client -dokumentaatiosta.