Azure Functions CI CD — DevOps

Always learning
5 min readApr 7, 2024

Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs.

It is a serverless compute service that enables user to run event-triggered code without having to provision or manage infrastructure. Being as a “trigger-based” service, it runs a script or piece of code in response to a variety of events.

Event-driven architecture (EDA) is a software design pattern that enables an organization to detect “events” or important business moments (such as a transaction, site visit, shopping cart abandonment, etc) and act on them in real time or near real time.

buymeacoffee ☕ 👈 Click the link

This pattern replaces the traditional “request/response” architecture where services would have to wait for a reply before they could move onto the next task. The flow of event-driven architecture is run by events and it is designed to respond to them or carry out some action in response to an event.

Event Types

  1. Simple Events
  2. Composite Events
  3. Temporal Events
  4. System Events
  5. Business Events
  6. Error Events
  7. Resource Events
  8. Lifecycle Events
  9. User Events
  10. Signal Events
  11. Transactional Events

Serverless enables automatic resource provisioning in response to events without the need to manage physical servers

Prerequisites

  1. Node.js (or) brew install node
  2. Azure Functions Core Tools
  3. Azure CLI
  4. An Azure account and an Azure Blob Storage account.

Node.js is a software platform built on Google’s V8 JavaScript engine. It makes use of an event-driven, non-blocking I/O model and a single-threaded event loop which allows high throughput and application scalability.

Azure Functions are a serverless compute service that allow you to run event-triggered code without having to explicitly provision or manage infrastructure.

Internally, Azure Functions work by utilizing the underlying Azure infrastructure to dynamically allocate resources and execute your code in response to events such as HTTP requests, timers, queues, or other triggers.

Create an Azure Function, you define the code to be executed in response to a specific event trigger. This code is then deployed to the Azure Functions runtime, which manages the execution of your code in response to the specified triggers.

The runtime takes care of scaling, resource allocation, and other operational aspects, allowing you to focus on writing the actual business logic of your functions.

The Azure Command-Line Interface (CLI) is a cross-platform command-line tool to connect to Azure and execute administrative commands on Azure resources.

Blob storage is a type of cloud storage for unstructured data. A “blob,” which is short for Binary Large Object, is a mass of data in binary form that does not necessarily conform to any file format. Blob storage keeps these masses of data in non-hierarchical storage areas called data lakes.

Create a new project

Import repository

A quick response (QR) code is a type of barcode that stores information and can be read by a digital device.

https://github.com/rishabkumar7/azure-qr-code.git

Create a Pipeline → Azure Repos Git → Select Git → Node.js function App to Linux on Azure.

Azure Functions is a serverless solution that allows you to write less code, maintain less infrastructure, and save on costs.

Create a Function app

Azure Pipelines is a cloud-based solution by Microsoft that automatically builds and tests code projects. It supports all major languages and project types. Azure Pipelines combines continuous integration (CI) and continuous delivery (CD) to test, build, and deliver code to any destination.

# # Node.js Function App to Linux on Azure
# Build a Node.js function app and deploy it to Azure as a Linux function app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- iac-implementation

variables:

# Azure Resource Manager connection created during pipeline creation
azureSubscription: '37035b62-6584-46fa-83fe-a8b418991be4'

# Function app name
functionAppName: 'ibrahims'

# Environment name
environmentName: 'ibrahims'
system.debug: true

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)

steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'

- script: |
cd qrCodeGenerator
npm install
npm run build --if-present
npm run test --if-present
displayName: 'Prepare binaries'

- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/qrCodeGenerator/GenerateQRCode/'
Contents: '**'
TargetFolder: '$(System.DefaultWorkingDirectory)/qrCodeGenerator/'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/qrCodeGenerator/'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/qrCodeGenerator/$(Build.BuildId).zip
replaceExistingArchive: true

- upload: $(Build.ArtifactStagingDirectory)/qrCodeGenerator/$(Build.BuildId).zip
artifact: drop

- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: $(environmentName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@2
inputs:
connectedServiceNameARM: 'Pay-As-You-Go (f30deb63-a417-4fa4-afc1-813a7d3920bb)'
appType: 'functionApp'
appName: 'ibrahims'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildID).zip'
deploymentMethod: 'zipDeploy'

Build Job is completed, Deploy running

Deploy job completed

Get the Application URL for QR code generator.

(OR)

Check with GUI. Go to function app. Click GeneratorQRCode

Code testing refers to running each line of code with a controlled input, and verifying if it performs the expected output. The goal is to identify bugs or errors during the SDLC.

Click Code+Test

Finally Test/Run the code

Automatically download the QR code in your download location.

That’s it.

Thank you 🙏 for taking the time to read our blog.

--

--

Always learning

கற்றுக் கொள்ளும் மாணவன்...