Load Impact and Azure DevOps Pipelines

Automated Performance Testing

Automate Load Testing in Your Azure DevOps Pipeline

Load Impact’s k6 open source load testing tool integrates with Azure DevOps Pipelines to automate tests. Run load tests as part of your nightly build process. Pass / fail results from the load test can automatically fail the build, as needed.

 

Azure Pipelines is a continuous integration (CI) and continuous delivery (CD) service. It works with your preferred Git provider and can deploy to most major cloud services. Start with your code on GitHub, GitLab, Bitbucket, or Azure Repos. You can automate the build, test, and deployment of your code to Microsoft Azure, Google Cloud, or Amazon Web Services (AWS).

 

Run a Local k6 Test from Azure Pipelines

 

Example k6 test script (JavaScript):

loadtests/local.js

import { check, group, sleep } from "k6";
import http from "k6/http";

export let options = {
   stages: [
       { duration: "10s", target: 15 },
       { duration: "20s", target: 15 },
       { duration: "10s", target: 0 }
   ],
   thresholds: {
       "http_req_duration": ["p(95)<250"]
   },
   ext: {
       loadimpact: {
           name: "test.loadimpact.com"
       }
   }
};

export default function() {
   group("Front page", function() {
       let res = http.get("http://test.loadimpact.com/");
       check(res, {
           "is status 200": (r) => r.status === 200
       });
       sleep(5);
   });
}

 

In azure-pipelines.yml config file we add a new script task to run k6 load test directly from Azure Pipelines agent:

steps:
# ...
- script: |
   k6 run loadtests/local.js
 displayName: Run k6 load test within Azure Pipelines

 

k6 Test Run from Azure Pipelinek6 Test Run from Azure Pipeline

 

Start Free Trial of k6 and Load Impact 4.0

Start My Free Trial

 

 

Run a Load Impact Cloud Execution Test from Azure Pipelines

 

k6 can also be used as a client to Load Impact's SaaS load testing solution. One of the advantages of using Load Impact Cloud Execution is extremely easy testing from multiple geographic locations (load zones).

 

Our test script is almost the same as the one presented above, but we'll change one small detail. We'll run our load test from two datacenters (Ashburn and Dublin). Not all of your customers live in a single location, so it's smart to test from multiple locations; the load can be generated from locations within the US, or from all over the globe. For a list of all available datacenters from which a load test can be run see k6 docs. Let's create a new file in our loadtests dir named cloud.js.

 

loadtests/cloud.js

import { check, group, sleep } from "k6";
import http from "k6/http";

export let options = {
   stages: [
       { duration: "10s", target: 15 },
       { duration: "20s", target: 15 },
       { duration: "10s", target: 0 }
   ],
   thresholds: {
       "http_req_duration": ["p(95)<250"]
   },
   ext: {
       loadimpact: {
           name: "test.loadimpact.com",
           distribution: {
               loadZoneLabel1: { loadZone: "amazon:us:ashburn", percent: 60 },
               loadZoneLabel2: { loadZone: "amazon:ie:dublin", percent: 40 }
             }
       }
   }
};

export default function() {
   group("Front page", function() {
       let res = http.get("http://test.loadimpact.com/");
       check(res, {
           "is status 200": (r) => r.status === 200
       });
       sleep(5);
   });
}

 

In azure-pipelines.yml config file add an additional step or modify your existing step that was running k6 locally.


# ...
- script: |
   k6 login cloud --token $(k6cloud.token)
   k6 cloud --quiet loadtests/cloud.js
 displayName: Run k6 cloud load test within Azure Pipelines
 

Now, you can push your new loadtests/cloud.js script alongside the new Pipelines script task to trigger a new build. You can see k6 output in the Azure Pipelines web UI, but for a more in-depth view and analysis of your test results go to Load Impact Insights.

 

Learn more about integrating with Azure Pipelines in this Knowledge Base article.

 

Load Impact Insights Load Test Results AnalysisLoad Impact Insights Load Test Results Analysis