Running Artillery on Azure DevOps

Integrating Artillery with Azure DevOps allows you to continuously track your service's performance while developing your applications. The following guide will show you how to load-test your services using the Azure Pipelines functionality that's a part of the family of Azure DevOps Services.

You’ll learn:

  • How to set up a pipeline in Azure DevOps to run your Artillery tests
  • How to generate and view Artillery test reports from Azure Pipelines
  • How to schedule your Artillery tests to run at a specific time

You can find the complete source code used in this guide in the Artillery CI/CD Examples GitHub repo (opens in a new tab).

Artillery test script example

In this guide, we'll use the following Artillery test script to run a load test on a simple API, creating 50 virtual users per second for 10 minutes and ensuring the aggregate maximum latency for the test is under 500 milliseconds:

config:
  target: 'http://lab.artillery.io'
  phases:
    - duration: 600
      arrivalRate: 50
  ensure:
    maxErrorRate: 1
    max: 500
 
scenarios:
  - name: 'Get a list of movies'
    flow:
      - get:
          url: '/movies'
          expect:
            - statusCode: 200

You can run an example of this test script and see it in action. (opens in a new tab)

Setting up Azure Pipelines

In an existing Azure DevOps project, go to the Pipelines section and create a new pipeline. This brings up the New Pipeline creation wizard. First, you need to point Azure to the code repository containing your Artillery test scripts to use for continuous integration. Azure DevOps supports the most popular code hosting services, but you can use any accessible Git or Subversion code repository:

Setting up Azure Pipelines - New pipeline step

For this guide, we'll use a GitHub code repository as an example. After granting permissions to GitHub, select the code repository containing your tests.

Setting up Azure Pipelines - Selecting code repository step

Next, Azure DevOps offers a few options to help configure your pipeline, depending on your code repository. In this guide, we'll select the Starter pipeline that provides the basics of an Azure Pipelines setup.

Setting up Azure Pipelines - Configure your pipeline step

In the last step of the setup wizard, you can modify the starter configuration file to suit your needs. The configuration file for the pipeline is defined through a file usually named azure-pipelines.yml at the root of your code repository. The configuration files use YAML syntax to determine the events that will trigger your workflow and the jobs and steps to execute.

You can modify the configuration file directly in the setup wizard. For this guide, the Artillery load test for the Socket.IO (opens in a new tab) service will run after pushing new code to the main branch of your repository. The pipeline will install the Node.js version 12 and install Artillery before executing the test script as part of the CI setup.

Update the configuration with the following contents:

trigger:
  - main
 
pool:
  vmImage: ubuntu-latest
 
steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '12.x'
    displayName: 'Install Node.js v12.x'
 
  - script: npm install -g artillery@latest
    displayName: 'Install Artillery'
 
  - script: artillery run tests/performance/socket-io.yml
    displayName: 'Execute load tests'

After updating the configuration file, click the Save and run button. You'll get a prompt to commit the azure-pipelines.yml file into your code repository. Once you commit the file into your repository's main branch, Azure DevOps will execute the load test:

Azure Pipelines - Successful Artillery test run

Generating and viewing Artillery test reports

Artillery can output a JSON file with additional details from the load test and use it to generate a self-contained HTML report (opens in a new tab).

First, your workflow needs to create a directory to place the test reports. Next, you can generate a JSON report when executing the Artillery load test. You can then use the report command (opens in a new tab) to generate the HTML report from the JSON file. Finally, you'll need to store the files as artifacts to access the reports upon completion of the workflow.

The configuration to accomplish these steps is the following:

trigger:
  - main
 
pool:
  vmImage: ubuntu-latest
 
steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '12.x'
    displayName: 'Install Node.js v12.x'
 
  - script: npm install -g artillery@latest
    displayName: 'Install Artillery'
 
  - script: mkdir $(System.DefaultWorkingDirectory)/reports
    displayName: 'Make reports directory'
 
  - script: artillery run --output reports/report.json tests/performance/socket-io.yml
    displayName: 'Execute load tests'
 
  - script: artillery report --output reports/report reports/report.json
    displayName: 'Generate HTML report'
 
  - publish: $(System.DefaultWorkingDirectory)/reports
    artifact: artillery-test-report

After successfully executing the load test, Azure DevOps will store the files inside the reports directory created as part of the workflow. You can find the published artifacts under the "Related" section of the test run results:

Azure Pipelines - Test run details Azure Pipelines - Artillery report artifacts

For more details on accessing the artifacts in Azure Pipelines, read the "Artifacts in Azure Pipelines overview" (opens in a new tab) section in the Azure DevOps documentation.

Scheduling Artillery load tests

You can also trigger an Azure Pipelines run on a recurring schedule which is helpful if you want to execute your Artillery load tests at a specific time. For instance, you may wish to load-test your production applications outside of peak hours.

The schedules trigger can be configured using the POSIX cron syntax (opens in a new tab), with the times in UTC. The following configuration will automatically trigger Azure Pipelines to run every day at midnight UTC:

schedules:
  - cron: '0 0 * * *'
    displayName: 'Midnight (UTC) performance test'
    branches:
      include:
        - main
 
pool:
  vmImage: ubuntu-latest
 
steps:
  - task: NodeTool@0
    inputs:
      versionSpec: '12.x'
    displayName: 'Install Node.js v12.x'
 
  - script: npm install -g artillery@latest
    displayName: 'Install Artillery'
 
  - script: artillery run tests/performance/socket-io.yml
    displayName: 'Execute load tests'

For more details about scheduling test runs in Azure DevOps, read the "Configure schedules for pipelines" (opens in a new tab) section in the Azure DevOps documentation.