{"id":3328,"date":"2025-04-10T10:40:30","date_gmt":"2025-04-10T10:40:30","guid":{"rendered":"https:\/\/loadfocus.com\/blog\/?p=3328"},"modified":"2025-04-10T10:40:31","modified_gmt":"2025-04-10T10:40:31","slug":"how-to-boost-performance-testing-integrating-loadfocus-api-with-jenkins","status":"publish","type":"post","link":"https:\/\/loadfocus.com\/blog\/2025\/04\/how-to-boost-performance-testing-integrating-loadfocus-api-with-jenkins","title":{"rendered":"How to Boost Performance Testing: Integrating LoadFocus API with Jenkins"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 5<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>\n<h2>Complete Step-by-Step Jenkins Integration Guide<\/h2>\n\n\n\n<p class=\"lead\">This comprehensive guide walks you through integrating the LoadFocus JMeter API Client with Jenkins to create automated, reliable performance testing pipelines that catch issues before they reach production.<\/p>\n\n\n\n<h2>Essential Setup: Getting Started with Jenkins Integration<\/h2>\n\n\n\n<h3>1. Securely Store Your LoadFocus Credentials in Jenkins<\/h3>\n\n\n\n<p>First, properly secure your LoadFocus API credentials in Jenkins:<\/p>\n\n\n\n<ol><li>Navigate to Jenkins Dashboard &gt; Manage Jenkins &gt; Manage Credentials<\/li><li>Select the appropriate credential domain (e.g., global)<\/li><li>Click &#8220;Add Credentials&#8221;<\/li><li>Add the following credentials:<ul><li>Kind: Secret text<\/li><li>Scope: Global<\/li><li>Secret: Your LoadFocus API key<\/li><li>ID: loadfocus-api-key<\/li><li>Description: LoadFocus API Key<\/li><\/ul><\/li><li>Repeat for your team ID with ID: loadfocus-team-id<\/li><\/ol>\n\n\n\n<h3>2. Create a Powerful Jenkins Pipeline<\/h3>\n\n\n\n<p>Create a Jenkinsfile in your repository with this configuration:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npipeline {\n    agent {\n        docker {\n            image 'node:16-alpine'\n        }\n    }\n    \n    environment {\n        LOADFOCUS_API_KEY = credentials('loadfocus-api-key')\n        LOADFOCUS_TEAM_ID = credentials('loadfocus-team-id')\n    }\n    \n    stages {\n        stage('Build') {\n            steps {\n                \/\/ Your build steps\n                sh 'npm install'\n                sh 'npm run build'\n            }\n        }\n        \n        stage('Test') {\n            steps {\n                \/\/ Your test steps\n                sh 'npm test'\n            }\n        }\n        \n        stage('Performance Test') {\n            steps {\n                \/\/ Install LoadFocus JMeter API Client\n                sh 'npm install -g @loadfocus\/loadfocus-api-client'\n                \n                \/\/ Configure LoadFocus API Client\n                sh 'loadfocus-api config set apiKey $LOADFOCUS_API_KEY'\n                sh 'loadfocus-api config set teamId $LOADFOCUS_TEAM_ID'\n                \n                \/\/ Run Performance Tests\n                sh '''\n                    loadfocus-api jmeter run-test \\\n                      --name &quot;Jenkins_${JOB_NAME}_${BUILD_NUMBER}&quot; \\\n                      --thresholds &quot;avgresponse&lt;=200,errors==0,p95&lt;=250&quot; \\\n                      --format json &gt; performance_results.json\n                '''\n                \n                \/\/ Archive the results\n                archiveArtifacts artifacts: 'performance_results.json', fingerprint: true\n            }\n        }\n        \n        stage('Deploy') {\n            when {\n                expression {\n                    return currentBuild.resultIsBetterOrEqualTo('SUCCESS')\n                }\n            }\n            steps {\n                \/\/ Your deployment steps\n                echo 'Deploying...'\n            }\n        }\n    }\n    \n    post {\n        always {\n            \/\/ Clean up workspace\n            cleanWs()\n        }\n    }\n}\n\n<\/pre>\n\n\n<h3>3. Configure Your Jenkins Job for Success<\/h3>\n\n\n\n<ol><li>Create a new Pipeline job in Jenkins<\/li><li>Configure the Pipeline to use your Jenkinsfile<\/li><li>Set up the appropriate SCM configuration to fetch your repository<\/li><\/ol>\n\n\n\n<h2>Advanced Configuration Techniques<\/h2>\n\n\n\n<h3>Parallel Testing: Run Multiple Tests Simultaneously<\/h3>\n\n\n\n<p>Optimize your pipeline with parallel performance tests:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npipeline {\n    agent any\n    \n    environment {\n        LOADFOCUS_API_KEY = credentials('loadfocus-api-key')\n        LOADFOCUS_TEAM_ID = credentials('loadfocus-team-id')\n    }\n    \n    stages {\n        \/\/ Previous stages...\n        \n        stage('Performance Tests') {\n            parallel {\n                stage('API Performance') {\n                    agent {\n                        docker {\n                            image 'node:16-alpine'\n                        }\n                    }\n                    steps {\n                        sh 'npm install -g @loadfocus\/loadfocus-api-client'\n                        sh 'loadfocus-api config set apiKey $LOADFOCUS_API_KEY'\n                        sh 'loadfocus-api config set teamId $LOADFOCUS_TEAM_ID'\n                        sh '''\n                            loadfocus-api jmeter run-test \\\n                              --name &quot;API_Performance_Test&quot; \\\n                              --thresholds &quot;avgresponse&lt;=150,errors==0&quot; \\\n                              --format json &gt; api_performance_results.json\n                        '''\n                        archiveArtifacts artifacts: 'api_performance_results.json', fingerprint: true\n                    }\n                }\n                \n                stage('UI Performance') {\n                    agent {\n                        docker {\n                            image 'node:16-alpine'\n                        }\n                    }\n                    steps {\n                        sh 'npm install -g @loadfocus\/loadfocus-api-client'\n                        sh 'loadfocus-api config set apiKey $LOADFOCUS_API_KEY'\n                        sh 'loadfocus-api config set teamId $LOADFOCUS_TEAM_ID'\n                        sh '''\n                            loadfocus-api jmeter run-test \\\n                              --name &quot;UI_Performance_Test&quot; \\\n                              --thresholds &quot;avgresponse&lt;=300,errors==0&quot; \\\n                              --format json &gt; ui_performance_results.json\n                        '''\n                        archiveArtifacts artifacts: 'ui_performance_results.json', fingerprint: true\n                    }\n                }\n            }\n        }\n        \n        \/\/ Next stages...\n    }\n}\n\n<\/pre>\n\n\n<h3>Scripted Pipeline: Maximum Flexibility for Complex Scenarios<\/h3>\n\n\n\n<p>For more control and conditional logic, use a scripted pipeline:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nnode {\n    def performanceTestPassed = false\n    \n    stage('Checkout') {\n        checkout scm\n    }\n    \n    stage('Build &amp;amp; Test') {\n        \/\/ Your build and test steps\n    }\n    \n    stage('Performance Test') {\n        docker.image('node:16-alpine').inside {\n            withCredentials([\n                string(credentialsId: 'loadfocus-api-key', variable: 'LOADFOCUS_API_KEY'),\n                string(credentialsId: 'loadfocus-team-id', variable: 'LOADFOCUS_TEAM_ID')\n            ]) {\n                sh 'npm install -g @loadfocus\/loadfocus-api-client'\n                sh 'loadfocus-api config set apiKey $LOADFOCUS_API_KEY'\n                sh 'loadfocus-api config set teamId $LOADFOCUS_TEAM_ID'\n                \n                try {\n                    sh '''\n                        loadfocus-api jmeter run-test \\\n                          --name &quot;Jenkins_${JOB_NAME}_${BUILD_NUMBER}&quot; \\\n                          --thresholds &quot;avgresponse&lt;=200,errors==0,p95&lt;=250&quot; \\\n                          --format json &gt; performance_results.json\n                    '''\n                    \n                    \/\/ Check if test passed by examining the JSON\n                    def testResults = readJSON file: 'performance_results.json'\n                    if (testResults.overallResult == 'PASSED') {\n                        performanceTestPassed = true\n                        echo &quot;Performance test passed!&quot;\n                    } else {\n                        echo &quot;Performance test failed to meet thresholds!&quot;\n                        \/\/ Optional: Fail the build\n                        \/\/ error &quot;Performance test failed&quot;\n                    }\n                } catch (Exception e) {\n                    echo &quot;Error running performance test: ${e.message}&quot;\n                }\n                \n                archiveArtifacts artifacts: 'performance_results.json', fingerprint: true\n            }\n        }\n    }\n    \n    stage('Deploy') {\n        if (performanceTestPassed) {\n            echo 'Deploying...'\n            \/\/ Your deployment steps\n        } else {\n            echo 'Skipping deployment due to performance test failure'\n        }\n    }\n}\n\n<\/pre>\n\n\n<h3>Shared Library: Create Reusable Performance Testing Components<\/h3>\n\n\n\n<p>Build reusable components for consistent testing across projects:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ vars\/performanceTest.groovy\ndef call(Map config = [:]) {\n    def testName = config.testName ?: &quot;Jenkins_${env.JOB_NAME}_${env.BUILD_NUMBER}&quot;\n    def thresholds = config.thresholds ?: &quot;avgresponse&lt;=200,errors==0,p95&lt;=250&quot;\n    def waitTimeout = config.waitTimeout ?: 1800\n    def resultsFile = config.resultsFile ?: &quot;performance_results.json&quot;\n    \n    docker.image('node:16-alpine').inside {\n        withCredentials([\n            string(credentialsId: 'loadfocus-api-key', variable: 'LOADFOCUS_API_KEY'),\n            string(credentialsId: 'loadfocus-team-id', variable: 'LOADFOCUS_TEAM_ID')\n        ]) {\n            sh 'npm install -g @loadfocus\/loadfocus-api-client'\n            sh 'loadfocus-api config set apiKey $LOADFOCUS_API_KEY'\n            sh 'loadfocus-api config set teamId $LOADFOCUS_TEAM_ID'\n            \n            sh &quot;&quot;&quot;\n                loadfocus-api jmeter run-test \\\\\n                  --name &quot;${testName}&quot; \\\\\n                  --thresholds &quot;${thresholds}&quot; \\\\\n                  --waitTimeout ${waitTimeout} \\\\\n                  --format json &gt; ${resultsFile}\n            &quot;&quot;&quot;\n            \n            archiveArtifacts artifacts: resultsFile, fingerprint: true\n            \n            \/\/ Return the test results\n            def testResults = readJSON file: resultsFile\n            return testResults\n        }\n    }\n}\n\n<\/pre>\n\n\n<p>Then in your Jenkinsfile:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@Library('my-shared-library') _\n\npipeline {\n    agent any\n    \n    stages {\n        stage('Performance Test') {\n            steps {\n                script {\n                    def results = performanceTest(\n                        testName: &quot;API_Performance_Test&quot;,\n                        thresholds: &quot;avgresponse&lt;=150,errors==0&quot;\n                    )\n                    \n                    if (results.overallResult != 'PASSED') {\n                        error &quot;Performance test failed&quot;\n                    }\n                }\n            }\n        }\n    }\n}\n\n<\/pre>\n\n\n<h2>Powerful Plugin Integrations<\/h2>\n\n\n\n<h3>Visualize Results with Performance Plugin<\/h3>\n\n\n\n<p>Use the Jenkins Performance Plugin to create insights from test results:<\/p>\n\n\n\n<ol><li>Install the Performance Plugin in Jenkins<\/li><li>Convert LoadFocus results to a format supported by the plugin (JMeter CSV or JUnit XML)<\/li><li>Configure your pipeline:<\/li><\/ol>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nstage('Performance Test') {\n    steps {\n        \/\/ Run LoadFocus test\n        sh '''\n            loadfocus-api jmeter run-test \\\n              --name &quot;Jenkins_${JOB_NAME}_${BUILD_NUMBER}&quot; \\\n              --thresholds &quot;avgresponse&lt;=200,errors==0,p95&lt;=250&quot; \\\n              --format json &gt; performance_results.json\n            \n            # Convert to JMeter CSV format (using a custom script)\n            node convert-to-jmeter.js performance_results.json performance_results.csv\n        '''\n        \n        \/\/ Use Performance Plugin\n        perfReport sourceDataFiles: 'performance_results.csv', \n                   errorFailedThreshold: 0, \n                   errorUnstableThreshold: 0, \n                   errorUnstableResponseTimeThreshold: '200'\n    }\n}\n\n<\/pre>\n\n\n<h3>Automated Email Notifications with Test Results<\/h3>\n\n\n\n<p>Keep your team informed with detailed test results:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npost {\n    always {\n        script {\n            if (fileExists('performance_results.json')) {\n                def results = readJSON file: 'performance_results.json'\n                def resultStatus = results.overallResult == 'PASSED' ? 'SUCCESS' : 'FAILURE'\n                def subject = &quot;Performance Test ${resultStatus}: ${env.JOB_NAME} #${env.BUILD_NUMBER}&quot;\n                \n                \/\/ Create email body\n                def body = &quot;&quot;&quot;\n                &lt;h2&gt;Performance Test Results&lt;\/h2&gt;\n                &lt;p&gt;&lt;strong&gt;Overall Result:&lt;\/strong&gt; ${results.overallResult}&lt;\/p&gt;\n                &lt;h3&gt;Results by Label&lt;\/h3&gt;\n                &lt;table border=&quot;1&quot;&gt;\n                &lt;tr&gt;&lt;th&gt;Label&lt;\/th&gt;&lt;th&gt;Result&lt;\/th&gt;&lt;th&gt;Avg Response&lt;\/th&gt;&lt;th&gt;Errors&lt;\/th&gt;&lt;\/tr&gt;\n                &quot;&quot;&quot;\n                \n                results.labels.each { label -&gt;\n                    body += &quot;&quot;&quot;\n                    &lt;tr&gt;\n                        &lt;td&gt;${label.label}&lt;\/td&gt;\n                        &lt;td&gt;${label.result}&lt;\/td&gt;\n                        &lt;td&gt;${label.metrics.avgresponse}ms&lt;\/td&gt;\n                        &lt;td&gt;${label.metrics.errors}&lt;\/td&gt;\n                    &lt;\/tr&gt;\n                    &quot;&quot;&quot;\n                }\n                \n                body += &quot;&lt;\/table&gt;&quot;\n                \n                emailext (\n                    subject: subject,\n                    body: body,\n                    to: 'team@example.com',\n                    attachmentsPattern: 'performance_results.json',\n                    mimeType: 'text\/html'\n                )\n            }\n        }\n    }\n}\n\n<\/pre>\n\n\n<h2>Expert Tips for Performance Testing in Jenkins<\/h2>\n\n\n\n<h3>1. Smart Timeout Handling<\/h3>\n\n\n\n<p>Set appropriate timeouts for long-running performance tests:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nstage('Performance Test') {\n    options {\n        timeout(time: 60, unit: 'MINUTES')\n    }\n    steps {\n        \/\/ Performance test steps\n    }\n}\n\n<\/pre>\n\n\n<h3>2. Strategic Conditional Execution<\/h3>\n\n\n\n<p>Run performance tests only when they&#8217;re most valuable:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nstage('Performance Test') {\n    when {\n        anyOf {\n            branch 'main'\n            branch 'develop'\n            tag pattern: &quot;v\\\\d+\\\\.\\\\d+\\\\.\\\\d+&quot;, comparator: &quot;REGEXP&quot;\n        }\n    }\n    steps {\n        \/\/ Performance test steps\n    }\n}\n\n<\/pre>\n\n\n<h3>3. Automated Scheduled Testing<\/h3>\n\n\n\n<p>Set up regular performance checks to catch regressions:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npipeline {\n    agent any\n    \n    triggers {\n        cron('0 0 * * *')  \/\/ Run at midnight every day\n    }\n    \n    stages {\n        \/\/ Pipeline stages\n    }\n}\n\n<\/pre>\n\n\n<h3>4. Customizable Parameterized Tests<\/h3>\n\n\n\n<p>Make your tests flexible with customizable parameters:<\/p>\n\n\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npipeline {\n    agent any\n    \n    parameters {\n        string(name: 'TEST_NAME', defaultValue: 'API_Performance_Test', description: 'Name of the LoadFocus test to run')\n        string(name: 'THRESHOLDS', defaultValue: 'avgresponse&lt;=200,errors==0', description: 'Performance thresholds')\n        string(name: 'WAIT_TIMEOUT', defaultValue: '1800', description: 'Maximum wait time in seconds')\n    }\n    \n    stages {\n        stage('Performance Test') {\n            steps {\n                \/\/ Run test with parameters\n                sh &quot;&quot;&quot;\n                    loadfocus-api jmeter run-test \\\\\n                      --name &quot;${params.TEST_NAME}&quot; \\\\\n                      --thresholds &quot;${params.THRESHOLDS}&quot; \\\\\n                      --waitTimeout ${params.WAIT_TIMEOUT} \\\\\n                      --format json &gt; performance_results.json\n                &quot;&quot;&quot;\n            }\n        }\n    }\n}\n\n<\/pre>\n\n\n<h2>Start Transforming Your Testing Pipeline Today<\/h2>\n\n\n\n<p>By integrating the LoadFocus API Client with Jenkins, you&#8217;ll create a powerful performance testing pipeline that catches issues early and ensures your applications deliver consistently excellent performance. Follow this guide to implement a robust, automated approach that makes performance testing an integral part of your development process.<\/p>\n\n\n\n<p>For more information, visit <a href=\"https:\/\/www.jenkins.io\/doc\/\">Jenkins documentation<\/a> and <a href=\"https:\/\/bitbucket.com\/loadfocus\/loadfocus-api-client\" class=\"broken_link\">LoadFocus API Client documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\"><\/span> <span class=\"rt-time\"> 5<\/span> <span class=\"rt-label rt-postfix\">minutes read<\/span><\/span>Complete Step-by-Step Jenkins Integration Guide This comprehensive guide walks you through integrating the LoadFocus JMeter API Client with Jenkins to create automated, reliable performance testing pipelines that catch issues before they reach production. Essential Setup: Getting Started with Jenkins Integration 1. Securely Store Your LoadFocus Credentials in Jenkins First, properly secure your LoadFocus API credentials&#8230;  <a href=\"https:\/\/loadfocus.com\/blog\/2025\/04\/how-to-boost-performance-testing-integrating-loadfocus-api-with-jenkins\" class=\"more-link\" title=\"Read How to Boost Performance Testing: Integrating LoadFocus API with Jenkins\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":3330,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,9,6,48],"tags":[513],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/3328"}],"collection":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/comments?post=3328"}],"version-history":[{"count":3,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/3328\/revisions"}],"predecessor-version":[{"id":3337,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/posts\/3328\/revisions\/3337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/media\/3330"}],"wp:attachment":[{"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/media?parent=3328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/categories?post=3328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/loadfocus.com\/blog\/wp-json\/wp\/v2\/tags?post=3328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}