Azure DevOps CI/CD

In this blog post, you can learn how to generate create a continuous integration release pipeline (CI) and deploy the published build to a Azure Webapp using continuous deployment (CD). The default VS2019 .Net Core WebAPI 'WeatherForecast' service is used In this example. As a prerequisite you need to upload the source code to an Azure Devops repo.

Build and Publish

There's some controversy as some folks REALLY like the "classic" pipeline while others like the .yaml (Yet Another Markup Language, IMHO) style. .yaml doesn't have all the features of the original pipeline yet, but it's close. It's primary advantage is that the pipeline definition exists as a single .yaml file and can be checked-in with your source code. That way someone (you, whomever) could import your GitHub or DevOps Git repository and it includes everything it needs to build and optionally deploy the app. The .yaml file live in the root directory of the application. The example shows

Configuration for build & publish:

trigger:
- master

#for image where app is built we are using a windows VM with VX2019 install on it
#because using a windows-2019 vm image no needed to also install .net core libraries
pool:
  vmImage: 'windows-2019' #other vm's are available

variables:
  buildConfiguration: 'Release'

steps:
#because all nuget packages used are all publically available no need to do a nuget restore it is done automatically here
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

- task: [email protected]
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
- task: [email protected]
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: 'myWebsiteName'

Publishing the CI build to a WebApp using CD

To start off you need to create a 'pipeline'. To this click the Create Pipeline button, top right, select the desired repo and follow the wizard to complete this task. Now you should presented with your pipeline as in the image below:

Azure Devops CI/CD screenshot

Now you need to create a 'release pipeline'. To do this click 'releases' on left menu then 'create release; top right. You will then be presented with a wizard as below.

Azure Devops CI/CD screenshot

Select an 'artifact', which in this example this a branch and version of our code in the repo.

Now you will see the as below a screen displaying the new 'release pipeline'

Azure Devops CI/CD screenshot

Now for this example, since the build and publish of our code is taken care of in the .yaml file in the root of our simple app source code, all we have to do is now deploy our published build to an Azurw WebApp. To do this click Edit top right on the 'release pipeline screen'.

Azure Devops CI/CD screenshot

The click on tasks for stage 1. Now we can add predefined task by click the + button to the right of Agent Job. All we need for this simple example is the Azure App Service Deploy task.

Azure Devops CI/CD screenshot

Details of which should look like these below, you can also click view .yaml (you are advised to save the contents for reference):-

Azure Devops CI/CD screenshot

Azure Devops CI/CD screenshot

Azure Devops CI/CD screenshot

So now you are all set to deploy your release pipleline to an Azure WebApp. Now click on the release pipeline, hover over stages, in this case there is only one, and click deploy. Click on deploy and again on the pop-wizard and wait for the release to be queued built and then deployed.

Azure Devops CI/CD screenshot

If all goes well you should get a Succeeded message under Stage 1. Click on the Succeeded message and you can see a list of job tasks and results.

Azure Devops CI/CD screenshot

Azure App Service Deploy task .yaml contents:

steps:
- task: [email protected]
  displayName: 'Azure App Service Deploy: WeatherForestsTest'
  inputs:
    azureSubscription: 'Free Trial (e53cb96a-ae8e-4a7d-b8c1-03ee273e9c12)'
    WebAppName: WeatherForestsTest
    packageForLinux: '$(System.DefaultWorkingDirectory)/_Test/myWebsiteName/s.zip'


Want help with Azure DevOps CI/CD ?


Get in Touch