Published in


End-to-End Testing

Run Cypress Tests using Docker on Azure DevOps Kubernetes Agents

Running E2E tests during a CI/CD Pipeline

Cypress is an end-to-end testing framework for web test automation. It enables front-end developers and test automation engineers to write automated web tests. It is a life-saving tool and helps developers quite a lot. And it is really easy to use, even easier when you decide to run Cypress tests via Docker. This feature helps us automate Cypress during a Continuous Integration process. All you have to do is run a simple Docker command inside a pipeline and let it do all the work.

In this article, I will demonstrate how to implement a pipeline that uses a Kubernetes agent running Cypress tests using Docker. There will be 7 steps:

1- Create a PAT in Azure DevOps

Sign in to your organization ({yourorganization}). And go to Personal Access Tokens section.

Click on “New Token”

For our purpose, it is enough to give Agent Pools(Read&Manage) and Auditing(Read Audit Logs) permissions. Save the token.

2- Create an Agent Pool by clicking on “Add Pool”

3- Create the image for the agent

Build your image docker build -t {your-registry-name}/agent/azure-agent:v1.0 .

NOTE: Put and Dockerfile into the same location

Before building your image, check the architecture of your Kubernetes nodes to configure FROM --platform=... ubuntu:18.04 section.

Note: If you want a docker ubuntu image in which you can run docker and systemctl commands, you can check petschenek/ubuntu-20.04-dind and petschenek/ubuntu-22.04-dind images.

4- Create the deployment on the Kubernetes cluster

Here, I want to explain some details about this deployment YAML. First, I created an emptyDir volume inside the pod. The filesystems of the containers that are going to be created inside the pod should be a normal filesystem, not a copy-on-write filesystem like AUFS and BTRFS. And since we cannot run AUFS on top of AUFS, I mounted “/var/lib/docker” on a normal filesystem with the help of emptyDir volume. Then I added “privileged: true” security context for docker to run successfully. Then the rest is easy. I just passed relevant information into the ado-agent-1 container as environment variables. Just for simplicity, I put the values of the environment variables in plain text but you should not do that :). Use at least Kubernetes secrets to store those values.

5- Check whether the agent is listening for jobs

You can check the pod logs where you should see “Listening for jobs” at the end:

and check the agent pool where agent-1 should be online:

6- Create the Azure Pipeline

You can also add the “baseUrl: http://{project-url}:{port}” and “video: true” options to the cypress.json file directly and remove the section where these values are passed as environment variables to the docker container.

7- Run the pipeline and observe the results

Check the test results

Download the screenshots and videos


As can be seen, we can run Cypress tests via Docker inside a Kubernetes pod. This gives us flexibility because we do not need to install a bunch of packages for Cypress to run and do not face dependency issues.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store