Azure Batch (Service) Automation using AzureDevOps CI/CD pipeline

Prashanth Kumar
5 min readJun 26, 2020

--

One of my current projects is working with Azure Batch, which we use to run an to processing large calculations. I saw most of the developers were deploying this application via manual process. Every-time they have to run Microsoft .net solution on their machines to generate zip file, manually set the version, and do this every time we needed a push to our Dev or prod environments.

I took the opportunity to automate this entire process end to end. Currently not much documentation available pertaining to straight forward approach, Hope this will help others as well.

Agenda behind writing this article is to achieve Azure batch service deployment along with required packages. Not many articles available over internet in order to achieve CI/CD automation using AzureDevOps pipeline.

My goal was to automate deployment, and to do this, we need to look at Batch clients. Microsoft splits the API structure into two different clients:

  • Management: Manage Batch accounts, storage, and account keys
  • Service: Manage compute nodes, pools, tasks and jobs.

Requirements

We need a couple of Azure Resources to get this to work.

  1. Azure Batch Account
  2. Azure Storage Account
  3. Azure Batch Account : while creating Azure batch account it needs to be followed in below work flow.
  • New Azure batch account creation
  • New Application creation
  • Application package assignment
  • New Job creation
  • New job schedule creation
  • Nodes restart

In order to achieve this i have created few ARM templates & 1 zip file (with .exe — dt.zip) which will does our work seamlessly.

Required ARM templates

all these templates have been uploaded at:

As a first step i have created a Build pipeline

Build pipeline to copy all files.

Click on 1published artifact and make sure it has all required files

Artifact files

Now lets start creating a Release Pipeline, as a part of this step we are going to achieve in following order

a. Need to update variables

b. Create new Azure storage

c. Create new Azure batch

d. Create new Application

e. Upload New application package

f. Create new job

g. Create new job schedule

h. Restart nodes

a. As a part of updating variables this create a new release job and click on Variables and update keyvalue pair based on your Org requirements.

Release pipeline variables

Make sure you update : Resource group name which is related with your Azure.

  • resourcegroupname
  • batchapplicationversion: One of the reason for using this variable is because everytime i generate a new .exe file i want to CI/CD pipeline to pick a new version automatically as counter.
  • Location: this is the location where you want to deploy Azure Batch.

As once you trigger a new release it will start creating below components

Release Pipeline

Now lets look into step by step to show how it really creates in Azure

  1. Storage account creation
New storage account-

2. AzureBlob file copy : this step will upload all required deployment and exe(zip) file to Blob storage.

3. New Azure Batch Service Deployment: this service will get deploy using “Deployment-application1.json” file.

It has deployed a new Batch service

4. Azure Batch Application creation: this will create a new application.

Release pipeline parameters
  • templateContainerUri $(templateContainerUri) -templateContainerSasToken $(templateContainerSasToken) -batchAccountName $(batchAccountName) -batchAccountPoolName $(batchAccountPoolName) -applicationStorageAccountName $(applicationStorageAccountName)

In Azure portal.

Applications
It will show recently uploaded zip file.

5. Azure batch application package creation: this will create and associate a new zip file to application, click on Pools → click on respective PoolID → go to application package & then you can see associated application and versioned zip file.

6. Azure batch job creation: next step is to create batch job in order to process all your application requests.

Release pipeline view:

Release pipeline- Job creation task

Azure View : click on jobs and then it will show all the jobs which are associated with that application pool1

7. New package assignment is optional based on application to application.

8. New schedule for newly created jobs:

Job schedules

9. Next step is for Nodes restart, first time when you create applications. Go to Pools → click on Pool ID → click on Nodes it will show the Name.

copy the name and put it in AzureDevOps Pipeline for restart.

Node 1 reboot

Next time when the pipeline runs and updates the packages it will restart Nodes as well.

sample json files are at: https://github.com/v6prask/AzureBatchService

Some of the articles which i took reference.

https://docs.microsoft.com/en-us/azure/batch/batch-ci-cd

https://github.com/Huachao/azure-content/blob/master/articles/batch/batch-automatic-scaling.md
https://docs.microsoft.com/en-us/azure/batch/batch-automatic-scaling

Hope this article is useful, let me know your thoughts/comments.

--

--

Prashanth Kumar
Prashanth Kumar

Written by Prashanth Kumar

IT professional with 20+ years experience, feel free to contact me at: Prashanth.kumar.ms@outlook.com

No responses yet