Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,46 @@ This repository contains a simple .NET 9 Web API that returns "Hello World" at t
- Working app service URL after deployment.

---

This project demonstrates how to setup a CI/CD pipeline using Azure Devops pipeline to deploy a .NET 9 Web API ('HelloApi')

# Infrastructure as a code using bicep
#provisioned:
- Azure App Service Plan (Linux, B1 tier)
- Azure Web App configured for .Net 9

so the bicep file is located at the root repo provisioning the above resources

## command to deploy
''' bash
az deployment group create \
--resource-group resource-group-name \
--template-file main.bicep
--parameters \
appServicePlanName="helloappserviceplan" \
webAppName="hello-dotnet9-webapp"

## deployment pipeline
since no azure subscription was not there this deployment won't be executed but if it is created we can execute it.

azure-pipelines.yaml is placed at the root which will run on every push to the main branch

we have multiple stages represnting the pipeline flow
Build stage:
- INSTALL .NET 9 SDK
- Restores NuGet dependencies
- Builds the project in Release mode
- publishes a zipped artifact (drop/)

Deploy stage:
- Deploys the build artifact to Azure App Service
- uses the AzureWebApp@1 task to deploy the .zip


#service connection is (expected)
azureSubscription: 'AzureSP-Devops'
this can be created in azure
under AzureDevops -> Project Settings -> Service Connections -> Azure ResourceManager

#Expected Application URL
https://hello-dotnet9-webapp.azurewebsites.net
69 changes: 69 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
trigger:
branches:
include:
- main

pool:
vmImage: 'ubuntu-latest'

variables:
buildConfiguration: 'Release'
outputDir: '$(Build.ArtifactStagingDirectory)/publish'

stages:
- stage: Build
displayName: 'Build Stage'
jobs:
- job: BuildApp
displayName: 'Build .NET 9 App'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '9.x.x'
installationPath: $(Agent.ToolsDirectory)/UseDotNet

- task: DotNetCoreCLI@2
displayName: 'Restore Dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'

- task: DotNetCoreCLI@2
displayName: 'Build Solution'
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
displayName: 'Publish Artifact'
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration $(buildConfiguration) --output $(outputDir)'
zipAfterPublish: true

- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(outputDir)'
ArtifactName: 'drop'
publishLocation: 'Container'

- stage: Deploy
displayName: 'Deploy Stage'
dependsOn: Build
jobs:
- deployment: 'Deploy Stage'
displayName: 'Deploy to Azure Web App'
environment: 'dev'
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp@1
displayName: 'Deploy Artifact to Web App'
inputs:
azureSubscription: 'AZURE-SERVICE-CONNECTION-NAME'
appName: 'hello-dotnet9-webapp'
package: '$(Pipeline.Workspace)/drop/**/*.zip'
40 changes: 40 additions & 0 deletions main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@description('Location for resources')
param location string = resourceGroup().location

@description('App Service Plan name')
param appServicePlanName string = 'helloappserviceplan'

@description('Web App name')
param webAppName string = 'hello-dotnet9-webapp'


// App service

resource appServicePlan 'Microsoft.Web/serverfarms@2022-09-01' = {
name: appServicePlanName
location: location
sku: {
name: 'B1'
tier: 'Basic'
}
kind: 'linux'
properties: {
reserved: true
}
}

// web app

resource webApp 'Microsoft.Web/sites@2022-09-01' = {
name: webAppName
location: location
kind: 'app,linux'
properties: {
serverFarmId: appServicePlan.id
siteConfig: {
linuxFxVersion: 'DOTNET|9.0'
alwaysOn: false
}
httpsOnly: true
}
}