Follow us

Azure DevOps (CICD Pipeline) - Part 2

 

In my previous article, we learned how to setup Azure CI pipeline and trigger on code commit and create artifact. If you have not yet gone through my first article on Azure DevOps, then please check this link: Azure DevOps (CICD Pipeline) - Part 1

 

Continuous to previous article, In this we will learn how to setup CD pipeline and have auto deployment of code/artifacts on my web server.

 

 

In this demo, I am using Amazon EC2 instance for my web server and Git repository for code push. So whenever I will be commiting code to my master branch first CI pipeline will run(which we have already learned in my previous article) and just after this it will automatically trigger CD(release) pipeline which will deploy my artifact to EC2 instance(web server).

 

To setup CD:

 

Create environments(this is which contains the servers/resources where you would like to push your code/artifacts):

Azure DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
sarejeevrej / TestPraject1 
4. 
Environments 
Environment 
prod 
Pipelines 
Environments 
Never deployed 
Never deployed 
Search 
New environrnent 
Last activity 
Mey 31 
Jun 5

On creating of environment, you need to add resource and select your resource/server like in my case I want to push my code to AWS EC2, so choose virtual server:

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Libran,' 
Task groups 
Deployment groups 
Test Plans 
sarejeevrej / TestPraject1 
4. 
Prod 
Pipelines 
Environments 
Prod 
Get started! 
Your environment is ready to use in pipeline 
environment : Prod 
To get full end to end traceability per resou 
Add resou rce 
Add resource 
Resource 
O 
Kubemetes 
o 
Aft Kuterretes 
Virtual machines 
virtue' rnscfnires

 

On next click, it will give you powershell script, which you need to run on your server(ec2 machine).

Prod 
Get started! 
Your environment is ready to use in pipeline 
environment : Prod 
To get full end to end traceability per resou 
Add resource 
Add resource 
Virtual machine resource 
Provider 
Generic provider 
Operating system 
Windows 
Registration script 
Run 
—O in Edmiristzt7'.•e 
n user pre-inserted in 
liter the czpié± script 
2. Once VM is registered, it nil' stet as environment resource 
Back 
Close

 

Just login to EC2 and open powershell run as admin and paste this script and hit enter. It might ask you for logic credential where you can use PAT token. To get pat token, from you Azure DevOps portal create new token with full access or copy existing token.

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
sarejeevrej / TestPraject1 
4. 
Prod 
Pipelines 
Environments 
prod 
Search 
69 
Preview features 
Profile 
Time and Locale 
Permissions 
Notifications 
Theme 
usage 
Personal access tokens 
SSH public keys 
Alternate credentials

 

Azure DevOps 
User settings 
Account 
AE profile 
Time and Locale 
CD Permissions 
Preferences 
Notifications 
9 Theme 
[Mb Usage 
Security 
RD Personal access tokens 
P Search 
Personal Access Tokens 
These cen Be used instead of a password far applications like Git or can be passed in the authorization heeder to access REST APIs 
New Token 
Token name 
Full AccessToken 
Full access 
Edit Regenerate 
Git https://dev.azure.com/sarajeevraj/on INDIA-RJHA 
Code (Read & write); Packaging (Read) 
Active 
Active 
Organization 
serajeevreJ 
serajeevreJ 
Expires on 
5/31/2022 
5/31/2022

post successful script run on you EC2, you can check your ec2 server manager, local server option, and search for services "pipeline" and it will start showing azure service there.

Server Manager 
Dashboard 
Local Server 
SERVICES 
All Servers 
Local Server 
Manage 
Tools 
Filtered results 2 of 221 total 
View 
TASKS 
File and Storage Ser.•ices 
pipelinel 
io IIS 
Server Name 
EC2AMAZ-T8TSM8H 
EC2AMAZ-TBTSM3H 
Display Name 
Azure Pipelines Agent (sarajeevraj..EC2AMAZ-T8TSMBH) 
Azure Pipelines Agent (sarajeevraj.TestProjectI-Dev Server 
- DG.EC2AMAZ-T3TSM8H) 
Service Name 
vs tsagent.saraj eevraj.. EC2AMAZ-T8TSM BH 
vstsagent.sarajeevraj.TestProject I-Dev Sen.'er 
- DG.EC2AMAZ-TBTSM3H 
Status 
Running 
Running 
Start Tyi 
Automa 
Autom a

Also after successful script run on your server(EC2), server start showing into Azure devops environment:

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
sarejeevrej / TestPraject1 
4. 
Dev 
Resources Deployments 
Name 
EC2AMAZ-TBTSMBH 
Pipelines 
Environments 
Latest job 
Dev 
Never deployed

 

With azure environment, you can also set approval and check - just click on your environment and then click on three dot(...) and select approval and check option. So that before code push to server, we want approval for that particular environment.

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
sarejeevrej 
4. 
Resources 
Name 
TestPraject 1 
Deployments 
Pipelines 
Environments 
Latest job 
Never deployed 
Search 
EC2AMAZ-TBTSMBH 
Add resource 
Edit 
a Security 
Approvals and checks 
Delete

 

Create deployment group - select your ec2 registered machine(you have registered with environment), in case you did not then here also you will get same powershell script to run on your server(EC2).

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Library' 
Task groups 
Deployment g roups 
Test Plans 
sarejeevrej 
TestPraject 1 
Pipelines 
Deployment groups 
4. 
Deployment groups 
Details Targets 
Deployment group name 
Description 
Deployment pool 
TestProject1 -test 
Dev-servers* 
Share O Security 
S Save 
O Help 
Type of target to register: 
Windows 
Registration script (PowerShelD 
P Search 
OSystem prerequisites E 
O Manage 
( [Security. Principi 
[Security. Principal. Windowsldentity] : : GetCurrent() ) . Islr 
[Security. Principal. WindowsBuiItInRoIe] "Aåninistrator"): 
aåninistrator PmærSheII prompt"} . PSV« 
throw "The minimLR version of Wi 
required by the script (3 . e) does not match the currentl) 
Windæas PowerSheII. " } (Test-path $env:SystemDri•, 
$env:SystemDriveVazagent cd azagenl 
. ToString() (Test-path (S 
$destFoIder;cd $destFoIder; break;}}; 
[System. Net . WebRequest] : : 
[Net. ServicePointManager] : : Securityprotocol;$securityprol 
[Net . SecurityProtocoIType] : : TIs12; 
[Net. ServicePointManager] : : Securityprotocol=$securityprol 
Net .*bCIient; $Uri= https://vstsagentpackage.azureedge.r 
agent-win-x64-2.187.2.zip• ; if($DefauItProxy -and ( -not 
$DefauItProxy. New-Ot 
Net . kbproxy ($DefauI tProxy. 6etProxy ( *Uri) . OriginalString,

 

Create release and select - type of deployment like you can search for IIS (in this case, I choose - IIS website and SQL database deployment)

sarejeevrej / TestPraject1 
Search all pipelines 
39 
Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Pipelines 
Releases 
TestProject1 Deployment To Dev 
Releases Deployments Analytics 
Test Pro 
e Stage 
New release pipeline 
Import release pipeline 
Releases 
O 
Release-I 
20210605.... 
Created 
6/5/20: 
V master

 

Pipelines 
Release: 
Al pipelines > 
Pipeline Tasks 
New release pipeline 
Variables Retention Options 
History 
Stage 1 
Select template 
Select a template 
Or stert with en Empty job 
Featured 
Artifacts 
-1- Add 
Stages 
Others 
Add an 
Schedule 
rc,t set 
IIS website and SQL database deployment 
Xlcymert Group: *Soy ASP,NET or ASP.NET Core 
IIS Website incl SQL cr physics 
cr kViV). 
IIS website and SQL database deployment to 
Azure Virtual Machines 
Xlcymert Group: ASP.NET or ASP.NET Core 
IIS int SQL to Azure 
Vitus (VV) it z set. 
IIS website and SQL database offline 
upgrade

Provide stage name:

All pipelines > 
Pipeline O Tasks 
New release pipeline 
S Save 
Variables Retention 
Options 
4. Add v 
History 
Create release 
[El Delete 
View releases 
Move v 
Artifacts 
+ Add 
Stages 
Add an 
artifact 
Schedule 
not set 
Deploy-To-Dev-S... 
C) 2 jobs, 3 tasks 
Stage 
De oy-To-Dev-Server 
Properties 
Name owners of stzge 
Stage name 
Deploy-To-Dev-Serve 
Stage owner

 

Add artifacts where you need to select your created pipeline:

Al pipelines > New release pipeline 
Pipeline O Tasks 
Variables Retention Options 
History 
Add an artifact 
Source type 
Artifacts 
-1- Add 
Stages 
o 
Azure Repos 
O 
Git*ub 
Add an artifact 
Schedule 
rc,t set 
Deploy-To-Dev-Se... 
0 2 jobs, 3 tasks 
5 more artifact types v 
Project O 
TestProject1 
Source (build pipeline) 
o 
TestProject1 (1) 
Default version 
o

Now click on task tab or from stage, you can click on tasks. Where you will find all the default tasks added to your release and you need to configure those tasks and if some of the tasks does not require(like in my current case I do not need DB deployment), so right click on that task and either remove or disable mit.

sarejeevrej / TestPraject1 
Pipelines / Releases 
All pipelines > New release pipeline 
Search 
S Save 
Create release 
Pipeline O Tasks 
Variables 
Deploy-To-Dev-Server 
C) Some 
IIS Deployment 
IIS Web App Manage 
O Some 
IIS Web App Deploy 
C Some 
SQL Deployment 
C) Some 
SQL DB Deploy 
O Some 
Retention Options 
Enable selected 
History 
View releases 
View VAML 
e: 
SQL Server database deploy O 
Task version O." 
Display name 
SQL DB Deploy 
Deploy SQL Using 
Sql Dacpac 
DACPAC File * O 
S(System. Defau ltWarkingDi 
Specify SQL using * Q) 
Disable selected task(s) 
Remove selected task(s) 
Clone task(s) 
Server Name * 
o

 

ALLCjpeIines > New release pipeline 
Pipeline O Tasks Variables Retention Options 
Deploy-To-Dev-Server 
IIS Deployment 
Run 
IIS Web App Manage 
IIS Web App Deploy 
IIS 
SQL Deployment 
næd 
Create release 
History 
Deployment group job O 
View releases 
Remove 
Display name 
SQL Deployment 
Deployment targets A 
Deployment group C) 
O This IS 
Required tags O 
Targets to deployto in parallel 
O 
O 
o

 

With Deployment stage task: select application/configuration type, provide IIS website name, pool name, binding etc.

serajeevrsj / TestProjectI 
/ Re—ses 
All pipelines > New release pipeline 
Pipeline O Tasks Variables Retention Options 
Deploy-To-Dev-Server 
IIS Deployment 
setting: 
IIS Web App Manage 
IIS Web App Deploy 
SQL Deployment 
setting: næd 
Seercfn 
Create release 
View releases 
History 
Stage name 
Deploy-To- Dev-server 
Parameters 
Configuration type 
IIS Website 
IIS Website 
Unlink al' 
IIS Web Applietion 
IIS Virtuz' Directory 
IIS App'icatior Pool 
Website name 
DevOpsTestProject I App 
binding Q) 
Add bindings 
http,'AII Unassigned:1002: 
Create or update app pool 
Application pool name 
DevOpsTestProject I A pp

 

With IIS deployment task, select created deployment group where your servers registered:

All pipelines > New release pipeline 
Pipeline O Tasks Variables Retention Options 
Deploy-To-Dev-Server 
IIS Deployment 
Run 
IIS Web App Manage 
IIS 
IIS Web App Deploy 
SQL Deployment 
setting: næd 
Create release 
View releases 
History 
Deployment group job O 
Display name 
IIS Deployment 
Deployment targets A 
Deployment group C) 
Required tags O 
I mstcfning targets in Dev Server - DG deployment group 
Targets to deploy to in parallel (D

 

With IIS web app deploy task - select "Take app offline" option, so that whenever code will deploy to IIS location it will take app offline first and will deploy the code and will again remove app from offline. This is require other you may get error ("file already in use") and your deployment will fail.

serajeevrsj / TestProjectI 
/ Re—ses / TestDevO.sReIezseFcrDevE... 
All pipelines > TestDevOpsReleaseForDevEnv 
Pipeline Tasks v Väriables Retention Options History 
Seercfn 
Deploy-To-Dev-Server 
IIS Deployment 
Run 
IIS Web App Manage 
IIS Web App Deploy 
Website Name 
DevOpsTestProject I App 
Virtual Application C) 
Package or Folder O 
S(System. ItWorki r, g 
File Transforms & Variable Substitution Options 
Advanced Deployment Options A 
Setparameters File O 
Remove Additional Files at Destination O 
Exclude Fles from the 
Take App Offline C) 
Additional Arguments O 
to t.ke App by peing 
zff'&htm in 'f Wed 
will be

 

Now save the release:

 

All pipelines > New release pipeline 
? i.erne 
Tasks Variables Retenticr Options 
ou can change release name here 
Deployment group job O 
Display 
E] Save 
Deploy-To-Dev-Server 
IIS Deployment 
IIS Web App Manage 
IIS Web App Deploy 
Save 
Folder 
Comment 
First time release setup for my test appl 
ment group 
Cancel

 

Now it will start showing your new created release. Now add release to this to trigger manual or automatic code/artifact push.

Azure DevOps 
TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
Library 
Task groups 
Deployment groups 
Test Plzns 
serajeevrsj / Test?rojectl 
p pipelines 
Seercfn 
TestDevOpsReleaseForDevEnv 
Releases Deployments Aralytics 
Edit 
Create release 
All releases 
+ New 
TestProjectI Deployment To Dev 
e Stage I 
TestDevOps Re I ease ForDevEnv 
No deplcyments found 
No releases found 
You can create a new release manua'ly cr setup triggers to create it 
Create a release

 

Here just to check, first time I choose manual trigger

serajeevrsj / Test?rojectl 
p pipelines 
TestDevOpsReleaseForDevEnv 
Releases Deployments Aralytics 
+ New v 
TestProjectI Deployment To Dev 
e Stage I 
TestDevOps Re I ease ForDevEnv 
No deplcyments found 
Create a new release 
9 Pipeline A 
Click sage to cinge its triwe to 
Stages for trigger change from automated to manual. 
Dep Server 
Artifacts A 
f.- for this 
o 
You en n 
_ Test?rojectl (I) 
Release description 
Cancel 
20210612.1

 

Now to run/trigger release manually, go to release just created and select stage and then deploy to stage:

TestP rojectl 
Overview 
Boards 
Rep 
Pipelines 
Pipelines 
Environments 
Releases 
Library 
Task groups 
p pipelines 
TestDevOpsReleaseForDevEnv 
Releases Deployments Aralytics 
+ New v 
TestProjectI Deployment To Dev 
e Stage I 
TestDevOpsReIeaseForDevEnv 
No deployments found 
Stagæ 
Release-I 
20210612.... 
P master

 

t TestDevOpsReleaseForDevEnv ) Release-I 
Pipeline VarizbLes History 
Release 
Manually triggered 
_ Test?rojectl (I) 
S Cancel 
Depboy v 
Deploy stage 
Deploy multiple 
C) Refresh 
Edit v 
Deploy-To-Dev-Server 
Summary Comm its Work Items 
Manuel trigger pending 
View logs 
Deploy-To-Dev-Servk 
O Not tep'cyed 
W.iting for manual trigger to start deployment 
Deploy 
Associated changes 
ammits and work items 
_ Test?rojectl (1) / 20210612.1 
master 
No previous deployment

 

Once deployment started, you can check the log by going into running release:

TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
Library 
p pipelines 
TestDevOpsReleaseForDevEnv 
Releases Deployments Aralytics 
+ New v 
TestDevO ps Re I ea seForDevEnv 
e Deploy-To-Dev-Server 
TestProjectI Deployment To Dev 
e Stage I 
Stagæ 
O 
Release-I 
20210612... 
P master

Azure DevOps 
TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
Library 
Task groups 
Deployment groups 
Test Plzns 
•rte cts 
serajeevrsj / TestProjectI 
t TestDevOpsReleaseForDevEnv 
Logs 
Y Filter by 
Start time •v 
EC2AMAZ-TBTSM3H 
Release-I 
Deploy -To -Dev -Server 
IIS Deployment 
EC2AMAZ-TBTSMBH 
Target: EC2AMAZ-T3TSM3H 
Initializejob succeeded 
Downlozd artifact - _ Testprojectl (I) - test-project I -artifacts 
IIS Web App Manzge succeeded 
IIS Web Deploy 
• succeeded 
Task 
Description 
Version 
Author 
Help 
: IIS web app deploy 
. Deploy a website or web application using "eb Deploy 
: e.184.2 
Microsoft Corporation 
https://docs.microsoft.

 

On successful deployment, you can go and check your EC2 IIS and see it must be auto created/hosted your website inside IIS when you run first time and also artifacts/code pushed inside IIS wwwroot folder.

Internet Information Services (IIS) Manager 
EC2AMAZ T8TSM8H 
Yiew Help 
Start Page 
Sites 
DevOpsTestProjectI App 
DevOpsTestProject1 App Home 
Filter: 
ASP.NET 
Authorizat... 
.NET Users 
SMTP E-mail 
Go • e Show All Group by. 
Area 
v EC2AMAZ T8TSM8H (EC2AMAZ-T8TSM8 
JO Application Pools 
v „ Sites 
Default Web Site 
> DevOpsTestProjectIApp 
e TestAppI 
Compilation 
Application 
Settings 
View 
.NET Error 
Pages 
Connection 
Strings 
Globalization 
Machine Key 
.NET Profile 
Pages and 
Controls 
.NET Roles 
Providers 
C] C] wwwroot 
Home 
* Quick access 
Desktop 
Documents 
Downloads 
Share 
ThisPC Local Disk 
Name 
inetpub 
root 
.NET Trust 
Levels 
Session State 
Type 
File folder 
JSON File 
JSON File 
Explore 
Edit Permissions... 
Edit Site 
Bindings... 
Basic Settings... 
View Applications 
View Virtual Directories 
Manage Website 
Restart 
Stop 
B rowse Website 
Browse ID02 (http) 
Search wwwroot 
Size 
appsettings.DeveIopmentjson 
appsettings.json 
Date modified 
6/5/2021 12:42 PM 
6/12/2021 1:20 PM 
6/12/2021 1:20 PM

fyi - On deployment, it will auto install IIS, .net framework runtime or any software which require to host that app and those software does not exists on ec2.

- In my case I used asp.net core web app to host, so everything was auto installed except .net core hosting bundle, which I had to install manually on server(ec2)

 

 

Now, to setup auto deployment trigger like I want whenever my pipeline is successful, I want my release deployment should run automatically and latest code-push/artifacts must be deployed to my servers(EC2) instead of pushing/trigger this manually:

Go to release and edit release pipeline:

Azure DevOps 
TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
Library 
Task groups 
Deployment groups 
serajeevrsj / TestProjectI 
t TestDevOpsReleaseForDevEnv 
Re—ses / 
Release-3 
Reese-3 
Pipeline VarizbLes History 
Release 
Continuous deployment 
_TestProjectI (I) O 
Deploy V S Cancel 
Stages 
C) Refresh 
Edit v 
Edit release 
Edit Pipeline 
Deploy-To-Dev-Serve 
Succeedet

Click on deployment trigger icon setup from artifact box and will open to model popup, where you need to enable the auto deployment trigger:

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Library' 
Task groups 
Deployment groups 
Test Plans 
sarejeevrej / TestPraject1 
All pipelines > 
Pipelines 
TestProject1 
Releases / TestProject1 Deployment To... 
Deployment To Dev 
Search 
R Save 
Create release 
View releases 
Pipeline Tasks 
Artifacts 
Test Project I 
Variables Retention Options History 
Add 
Stages 
4. Add v 
Dev Server To Depl... 
I job, 2 tasks 
Continuous deployment trigger 
Build: _ Test-project I 
Enabled 
Creates release every time new build is available. 
Build branch filters O 
Type 
Include 
Build branch 
master 
Build tags 
Schedule 
not set 
Add •v 
Pull request trigger 
Build: _ Test-project I 
Disabled 
C) Enabing this will create re—se every time seeded artifact is available as pört Ota pun 
request work-flue

 

Now whenever you push code to master branch, first your pipeline will trigger and on pipeline successful, immediately after release deployment pipeline will start like below:

Azure DevOps 
TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
Library 
Task groups 
serajeevrsj / Test?rojectl 
p pipelines 
Seercfn 
Edit 
TestDevOpsReleaseForDevEnv 
Releases Deployments Aralytics 
Create release 
All releases v 
+ New v 
TestDevOps Re lea se ForDevEnv 
Deploy-To-Dev-Server 
Stag 
O 
O 
Release-2 
20210612.... 
Release-I 
20210612.... 
P master 
P master

 

 

 

Categories/Tags: azure devops~cicd

Recent Articles

1

AWS Saving Plan - Cost optimization tips

2
3

AWS RDS Key Concepts & Why you should use it?

4
5

Open-Search/Kibana - Multi Tenancy Setup

See All Articles