Jenkins
Tento navod vysvetluje, ako integrovat LoadFocus JMeter API klienta s Jenkins na automatizovane testovanie vykonnosti.
Kroky nastavenia
1. Ulozenie povereni v Jenkins
Najprv bezpecne ulozte vase poverenia LoadFocus API v Jenkins:
- Prejdite na Jenkins Dashboard > Manage Jenkins > Manage Credentials
- Vyberte prislusnu domenu povereni (napr. global)
- Kliknite na "Add Credentials"
- Pridajte nasledujuce poverenia:
- Kind: Secret text
- Scope: Global
- Secret: Vas LoadFocus API kluc
- ID: loadfocus-api-key
- Description: LoadFocus API Key
- Zopakujte pre vas team ID s ID: loadfocus-team-id
2. Vytvorenie Jenkins Pipeline
Vytvorte Jenkinsfile vo vasom repozitari:
pipeline {agent {docker {image 'node:16-alpine'}}environment {LOADFOCUS_API_KEY = credentials('loadfocus-api-key')LOADFOCUS_TEAM_ID = credentials('loadfocus-team-id')}stages {stage('Build') {steps {sh 'npm install'sh 'npm run build'}}stage('Test') {steps {sh 'npm install'sh 'npm test'}}stage('Performance Test') {steps {sh 'npm install -g @loadfocus/loadfocus-api-client'sh 'loadfocus-api config set apikey $LOADFOCUS_API_KEY'sh 'loadfocus-api config set teamid $LOADFOCUS_TEAM_ID'sh '''loadfocus-api jmeter run-test \--name "Jenkins_${JOB_NAME}_${BUILD_NUMBER}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json'''archiveArtifacts artifacts: 'performance_results.json', fingerprint: true}}stage('Deploy') {when {expression {return currentBuild.resultIsBetterOrEqualTo('SUCCESS')}}steps {echo 'Deploying...'}}}post {always {cleanWs()}}}
3. Konfiguracia ulohy Jenkins
- Vytvorte novu ulohu Pipeline v Jenkins
- Nakonfigurujte Pipeline na pouzitie vasho Jenkinsfile
- Nastavte prislusnu konfiguraciu SCM na nacitanie vasho repozitara
Tipy pre integraciu Jenkins
Spracovanie casovych limitov: Nastavte casove limity pre dlhotrvajuce testy vykonnosti:
stage('Performance Test') {options {timeout(time: 60, unit: 'MINUTES')}steps {// Performance test steps}}Podmienene spustenie: Spustajte testy vykonnosti iba na konkretnych vetvach:
stage('Performance Test') {when {anyOf {branch 'main'branch 'develop'}}steps {// Performance test steps}}Planované testovanie: Spustajte testy vykonnosti podla planu:
pipeline {agent anytriggers {cron('0 0 * * *') // Run at midnight every day}stages {// Pipeline stages}}Parametrizovane testy: Povolte prisposobenie parametrov testu.
Pre viac informacii pozrite dokumentaciu Jenkins a dokumentaciu LoadFocus API klienta.