While developing applications on Azure, it's often necessary to integrate with Azure Storage. Notably, Azure Functions development always needs Azure Storage. Fortunately, Azure Storage Emulator can literally emulate the connection. For unit testing, it's rarely necessary, but it is for integration testing or end-to-end testing for some scenarios. Running the emulator is OK at my local machine. How can it be run in a CI/CD pipeline?
Throughout this post, I'm going to discuss how to run Azure Storage Emulator in Azure DevOps Pipelines.
Azure Storage Emulator
You can directly download and install Azure Storage Emulator from this link. As it's also a part of Azure SDK, it's already installed on Microsoft-hosted Agent. Therefore, running the commands below can let the emulator up and run through the pipeline. Let's have a look.
The agent is always spun up whenever each build is triggered. Therefore, define a task to initialise a local database for the emulator.
Once initialised, then run the emulate like this:
You can run separate tasks for both commands or run at once, like below:
If you prefer using YAML pipeline, add the
CommandLine task and enter both commands like this:
It's not that hard.
However, there's a slight problem on this approach. This emulator runs only on Windows machine. In other words, if you want to run this emulator, the build agent MUST be running Windows OS like
vs2015-win2012r2. Many applications we build nowadays support cross-platform, which is not a problem. But there are still many applications that only support a specific OS other than Windows. This OS-specific application will be the problem. What will be the solution for these cases?
Azurite is the future storage emulator platform. Azurite supersedes the Azure Storage Emulator. Azurite will continue to be updated to support the latest versions of Azure Storage APIs.
Therefore, using this tool also needs to be considered as an alternative.
Unfortunately, we need to install Azurite first before anything else, as it's not yet the default tool installed on the agent. As it's an npm package, simply run the command like below for installation. Make sure you run
sudo command to install the package.
At the time of this writing, the latest version of Azurite is
3.2.0-preview. However, you can still install the latest stable version of
Once installed, run the command below to run Azurite. Also, make sure that you run Azurite in the background by adding
& at the end of the command. If it's not running in the background, the pipelines won't proceed to the next step.
The YAML pipeline representation might look like:
So far, we've walked through how to run Azure Storage Emulator within Azure Pipelines. We've also discussed how Azurite can be installed and run within Azure Pipelines as an alternative to Azure Storage Emulator.
Get Azure DevOps
Are you interested in playing around Azure Storage Emulator or Azurite on Azure DevOps? Sign-up now. It's free!