Jenkins
Diese Anleitung erklaert, wie Sie den LoadFocus JMeter API Client mit Jenkins fuer automatisierte Leistungstests integrieren.
Einrichtungsschritte
1. Anmeldedaten in Jenkins speichern
Speichern Sie zunaechst Ihre LoadFocus API-Zugangsdaten sicher in Jenkins:
- Navigieren Sie zu Jenkins Dashboard > Manage Jenkins > Manage Credentials
- Waehlen Sie die entsprechende Credential-Domain (z. B. global)
- Klicken Sie auf "Add Credentials"
- Fuegen Sie folgende Credentials hinzu:
- Kind: Secret text
- Scope: Global
- Secret: Ihr LoadFocus API-Schluessel
- ID: loadfocus-api-key
- Description: LoadFocus API Key
- Wiederholen Sie dies fuer Ihre Team-ID mit ID: loadfocus-team-id
2. Jenkins-Pipeline erstellen
Erstellen Sie eine Jenkinsfile in Ihrem Repository:
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 {// Your build stepssh 'npm install'sh 'npm run build'}}stage('Test') {steps {// Your test stepssh 'npm test'}}stage('Performance Test') {steps {// Install LoadFocus JMeter API Clientsh 'npm install -g @loadfocus/loadfocus-api-client'// Configure LoadFocus API Clientsh 'loadfocus-api config set apikey $LOADFOCUS_API_KEY'sh 'loadfocus-api config set teamid $LOADFOCUS_TEAM_ID'// Run Performance Testssh '''loadfocus-api jmeter run-test \--name "Jenkins_${JOB_NAME}_${BUILD_NUMBER}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json'''// Archive the resultsarchiveArtifacts artifacts: 'performance_results.json', fingerprint: true}}stage('Deploy') {when {expression {return currentBuild.resultIsBetterOrEqualTo('SUCCESS')}}steps {// Your deployment stepsecho 'Deploying...'}}}post {always {// Clean up workspacecleanWs()}}}
3. Jenkins-Job konfigurieren
- Erstellen Sie einen neuen Pipeline-Job in Jenkins
- Konfigurieren Sie die Pipeline zur Verwendung Ihrer Jenkinsfile
- Richten Sie die entsprechende SCM-Konfiguration ein, um Ihr Repository abzurufen
Erweiterte Konfiguration
Deklarative Pipeline mit parallelen Tests
Mehrere Leistungstests parallel ausfuehren:
pipeline {agent anyenvironment {LOADFOCUS_API_KEY = credentials('loadfocus-api-key')LOADFOCUS_TEAM_ID = credentials('loadfocus-team-id')}stages {// Previous stages...stage('Performance Tests') {parallel {stage('API Performance') {agent {docker {image 'node:16-alpine'}}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 "API_Performance_Test" \--thresholds "avgresponse<=150,errors==0" \--format json > api_performance_results.json'''archiveArtifacts artifacts: 'api_performance_results.json', fingerprint: true}}stage('UI Performance') {agent {docker {image 'node:16-alpine'}}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 "UI_Performance_Test" \--thresholds "avgresponse<=300,errors==0" \--format json > ui_performance_results.json'''archiveArtifacts artifacts: 'ui_performance_results.json', fingerprint: true}}}}// Next stages...}}
Tipps fuer die Jenkins-Integration
Timeout-Behandlung: Timeouts fuer lang laufende Leistungstests festlegen:
stage('Performance Test') {options {timeout(time: 60, unit: 'MINUTES')}steps {// Performance test steps}}Bedingte Ausfuehrung: Leistungstests nur auf bestimmten Branches ausfuehren:
stage('Performance Test') {when {anyOf {branch 'main'branch 'develop'tag pattern: "v\\d+\\.\\d+\\.\\d+", comparator: "REGEXP"}}steps {// Performance test steps}}Geplante Tests: Leistungstests nach Zeitplan ausfuehren:
pipeline {agent anytriggers {cron('0 0 * * *') // Run at midnight every day}stages {// Pipeline stages}}Parametrisierte Tests: Anpassung von Testparametern ermoeglichen:
pipeline {agent anyparameters {string(name: 'TEST_NAME', defaultValue: 'API_Performance_Test', description: 'Name of the LoadFocus test to run')string(name: 'THRESHOLDS', defaultValue: 'avgresponse<=200,errors==0', description: 'Performance thresholds')string(name: 'WAIT_TIMEOUT', defaultValue: '1800', description: 'Maximum wait time in seconds')}stages {stage('Performance Test') {steps {// Run test with parameterssh """loadfocus-api jmeter run-test \\--name "${params.TEST_NAME}" \\--thresholds "${params.THRESHOLDS}" \\--waitTimeout ${params.WAIT_TIMEOUT} \\--format json > performance_results.json"""}}}}
Weitere Informationen finden Sie in der Jenkins-Dokumentation und der LoadFocus API Client-Dokumentation.