Document

SUBSCRIBE TO GET FULL ACCESS TO THE E-BOOKS FOR FREE 🎁SUBSCRIBE NOW

Professional Dropdown with Icon

SUBSCRIBE NOW TO GET FREE ACCESS TO EBOOKS

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)

Example-1

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
pool:
  vmImage: ‘ubuntu-latest’
# Steps are the part of a job which are to be executed on vm
steps:
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
pool:
  vmImage: ‘ubuntu-latest’
# jobs to execute the steps on vm
jobs:
job: Firstjob
  timeoutInMinutes: 10
  steps:
  – bash: echo “The First job”
 
job: Secondjob
  steps:
  – bash: echo “Our Second Pipeline”


Output




Azure pipeline for an Asp.net Core application

1. In Azure pipelines select New Pipeline.

2. Select Azure Repo which has asp.net 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:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
 
# Trigger indicates that whenever there is a change in the master branch then
# this pipeline will be executed automatically
trigger:
master
 # VM image is windows latest
pool:
  vmImage: ‘windows-latest’
 # variables are defined whichare used in the tasks
variables:
  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
steps:
task: NuGetToolInstaller@1
 
task: NuGetCommand@2
  inputs:
    restoreSolution: ‘$(solution)’
 
task: VSBuild@1
  inputs:
    solution: ‘$(solution)’
    msbuildArgs: ‘/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation=”$(build.artifactStagingDirectory)\WebApp.zip” /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.

Share your love

Leave a Reply

Your email address will not be published. Required fields are marked *