Saturday, May 28, 2022

Azure Devops -Azure Pipeline


Azure pipeline is a process to provide CI/CD pipeline automation process. It has the following compoment.

Build Process:- Azure pipeline creates a virtual machine( which you can't see in the VMS) and source code ( From Azure Repos) is built on this virtual machine. This virtual machine could be windows/Linux/Mac. It is an intermediate environment to build the application. Once the application is built then this virtual machine is disposed of.

This VM is an agent which is a part of the agent pool and there are different types of agents depending upon which type of VM is selected in the Azure pipeline

Let's Create the first Azure Pipeline using MS-hosted Agent (using the script not the classic editor in this example)


1. Select the Azure pipelines and then click on Create Pipeline

2. Select the Azure Repo where the source code is available ( It can be Azure Repo/ Github/Bitbucket etc). You can select Azure Repo in case the code is in the Azure repository.

3. Select the repository where the code is available.

4. Once the repository is selected then it shows the pipeline code so let's replace the code with the below code.

# Agent pool is the collection of vms
# in the below code, ubuntu latest vm image is refered for pipeline to deploy the code
  vmImage: 'ubuntu-latest'
# Steps are the part of a job which are to be executed on vm
- bash: echo "Azure Basic Pipeline Code"

5. Click on Save and Run button to run the pipeline, select the branch as master and click on run.

6. Azure pipeline should run a job 

Example -2

Follow the same steps as mentioned above to create a new pipeline using the below code. In this example, there are multiple jobs that are configured in the pipeline

# Agent pool is the collection of vms
# in the below code, ubuntu latest vm image is refered for pipeline to deploy the code
  vmImage: 'ubuntu-latest'
# jobs to execute the steps on vm
- job: Firstjob
  timeoutInMinutes: 10
  - bash: echo "The First job"
- job: Secondjob
  - bash: echo "Our Second Pipeline"


Azure pipeline for an Core application

1. In Azure pipelines select New Pipeline.

2. Select Azure Repo which has core app source code.

3. Select the pipeline build platform (Aspnet core) .NET Framework

4. Write the pipeline code similar to the given below

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# Trigger indicates that whenever there is a change in the master branch then
# this pipeline will be executed automatically
- master
 # VM image is windows latest
  vmImage: 'windows-latest'
 # variables are defined whichare used in the tasks
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
 # job with multiple steps and steps are furhter having one or multiple tasks
 # NuGetToolInstaller@1 it is inbuilt step to download NuGet tool on the VM
 # NuGetToolInstaller@2 it is inbuilt step to Configure the NugetCommand for the solution (defined as variable)
 # VSBuild@1 to build the solution using MSBuild with given parameters
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
    restoreSolution: '$(solution)'
- task: VSBuild@1
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

5. Save and run the pipeline.

Note:- Change the source code in the master branch and you will notice that the pipeline is executed automatically.


Post a Comment