CircleCI
This guide explains how to integrate the LoadFocus JMeter API Client with CircleCI for automated performance testing. --name is always the exact name of a JMeter test you already saved in LoadFocus.
Setup Steps
1. Add Environment Variables
Store your LoadFocus API credentials as environment variables in CircleCI:
- Navigate to your project in CircleCI
- Go to Project Settings > Environment Variables
- Add the following variables:
LOADFOCUS_API_KEY: Your LoadFocus API keyLOADFOCUS_TEAM_ID: Your LoadFocus team ID
2. Configure CircleCI Workflow
Create or update your .circleci/config.yml file to include performance testing:
version: 2.1jobs:performance_test:docker:- image: cimg/node:24.22steps:- checkout- run:name: Install LoadFocus JMeter API Clientcommand: npm install -g @loadfocus/loadfocus-api-client- run:name: Configure LoadFocus API Clientcommand: |loadfocus-api config set --apikey $LOADFOCUS_API_KEY --teamid $LOADFOCUS_TEAM_ID- run:name: Run Performance Testscommand: |# --name is the exact name of a test you saved in LoadFocusloadfocus-api jmeter run-test \--name "My_JMeter_Test" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json- store_artifacts:path: performance_results.jsondestination: performance-test-results# run-test exits with code 1 when a threshold is missed, which fails this job.# performance_results.json starts with a few progress lines before the JSON object:# keep only the JSON with: sed -n '/^{$/,$p' performance_results.json > results.jsonworkflows:version: 2build_test_deploy:jobs:- build_and_test- performance_test:requires:- build_and_test- deploy:requires:- performance_testfilters:branches:only: main
3. Fail the Build on Performance Issues
The "Run Performance Tests" step above already fails the build when a threshold is missed, because run-test exits with code 1 and CircleCI stops the job on a non-zero exit. To print your own message first, handle the failure on the same line:
- run:name: Run Performance Testscommand: |loadfocus-api jmeter run-test \--name "My_JMeter_Test" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json || {echo "Performance test failed to meet thresholds"exit 1}
Advanced Configuration
Parallel Testing
For running multiple performance tests in parallel:
performance_tests:docker:- image: cimg/node:24.22parallelism: 3steps:- checkout- run:name: Install LoadFocus JMeter API Clientcommand: npm install -g @loadfocus/loadfocus-api-client- run:name: Configure LoadFocus API Clientcommand: |loadfocus-api config set --apikey $LOADFOCUS_API_KEY --teamid $LOADFOCUS_TEAM_ID- run:name: Run Performance Testscommand: |# Get test name based on indexTESTS=("API_Test" "Frontend_Test" "Database_Test")INDEX=$(( $CIRCLE_NODE_INDEX % 3 ))TEST_NAME=${TESTS[$INDEX]}echo "Running test: $TEST_NAME"loadfocus-api jmeter run-test \--name "$TEST_NAME" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > "performance_results_${TEST_NAME}.json"- store_artifacts:path: performance_results_*.jsondestination: performance-test-results
Tips for CircleCI Integration
Resource Allocation: Ensure your CircleCI plan has sufficient resources for running performance tests, especially if they're long-running.
Timeout Settings: For longer tests, adjust the job timeout in CircleCI:
- run:name: Run Performance Testscommand: loadfocus-api jmeter run-test --name "Test_Name" --wait-timeout 3600no_output_timeout: 60mConditional Testing: Only run performance tests on specific branches or for specific commits:
performance_test:# Only run if commit message contains [PERF-TEST]when:condition:or:- equal: [ main, << pipeline.git.branch >> ]- matches:pattern: ".*\\[PERF-TEST\\].*"value: << pipeline.git.commit.message >>Notifications: Set up notifications for performance test failures:
- run:name: Notify on Performance Test Failurecommand: |curl -X POST -H "Content-Type: application/json" \-d "{\"text\":\"Performance test failed for $CIRCLE_PROJECT_REPONAME\"}" \$SLACK_WEBHOOK_URLwhen: on_fail
For more information, refer to the CircleCI documentation and the LoadFocus API Client documentation.