Follow us

Azure DevOps (CICD Pipeline) - Part 1

 

In this article we will learn how to setup Azure CI Pipeline to trigger build on code commit and generate artifact which we can use then to host and run the app.

 

You must have azure account to access the devops portal/board. You can login with you github account to have free access. On sign up, you create organization and then inside that organization you start creating multiple projects and setup CICD and azure board for your projects.

https://azure.microsoft.com/en-us/services/devops/boards

If you are using free account then on running pipeline, you might get error "No hosted parallelism has been purchased or granted", so Microsft now does not allow running pipeline free by default, so for that you can send email on by providing organization name and your project details: "azpipelines-freetier@microsoft.com".

C 
Azure DevOps 
New organization 
https://dev.azure.com/sarajeevraj 
sarajeevraj 
Projects My work items My pull requests 
HelloWorldApp 
Search 
Not syncing 
+ New project 
Y Filter projects 
TestProject1

 Here - "sarajeevraj" is my organization name and inside that, I can create multiple projects and manage my work items(tickets) and pull requests(PR-code review).

 

Create azure repository + sample code app/code push to repository:

  • Login to Azure DevOps portal and create new project.
  • Open project and navigate to repository file and copy the clone URL which you can use with your IDE to clone the repository on your local system and commmit some code.C 
Azure DevOps 
HelloWorldApp 
Boards 
Repos 
Files 
Commits 
Pushes 
Branches 
Tags 
Pull requests 
Pipelines 
Test Plans 
https://dev.azure.com/sarajeevraj/_git/HeIloWorldApp 
sarejeevrej 
4. 
HelloWarIdApp / Repos 
Files 
HellaWorldApp v 
HelloWorldApp is empty. Add some code! 
Clone to your computer 
SSH https://saraJeevraJ@dev.azure.cam/sarajeevraj/HelloWarldApp/_git/+ 
Generate Git Credentials 
OR 
P Search 
Clone in VS Code 
O Hi'.'irg problems authenticeting in Gif? sure to get latest version Git for Windows or our p'ugins for IntelliJ, Eclipse: Android St'Jdio or Windows command 
Push an existing repository from command line 
git remote add origin 
https://serajeevraj@dev.azure.com/sarajeevraj/HellaWorldApp/_git/HelloWarldApp 
Import a repository 
Import
  • After successful clone, create sample app and push/code the code. (In this case, I have created .net core web application for this demo).

Now we have sample app available with repository created, so lets setup CI pipeline:

 

To create pipeline with publish artifacts:

Go to inside project, and from left panel, click pipeline and create pipeline.

Select code source:

C 
Azure DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Library' 
Task groups 
Deployment groups 
Test Plans 
Altifects 
https://dev.azure.com/sarajeevraj/TestProject1/_apps/hub/ms.vss-build-web.ci-designer-hub 
sarejeevrej / TestPraject1 
Pipelines 
4. 
Connect 
New pipeline 
Select 
Configure 
Review 
Where is your code? 
Azure Repos Git YAML 
Free Git repositcr•es, End code 
Bitbucket Claud YAML 
o 
GitHub YAMI_ 
Home tc the wort's Isrge-st community cf de'.elcpers 
o 
GitHub Enterprise Server AML 
self-rosted version of GitHu5 Enterprise 
Other Git 
generic Git 
Subversion 
Centrzlizet ccrtro' by Apache 
use the classic editor to create a pipeline without YAML.

Select project for the pipeline:

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
pioelines 
4. 
sarejeevrej 
Connect 
New pipeline 
TestPraject1 / 
Pipelines 
Select 
Configure 
Review 
Select a repository 
Filter by key.',crds 
TestProject 1 
TestProject1

 

Select framework used for your project:

ê' nôuuoD 
p.puruvel_uex 
y•opu1P,•, 
EN') EN•asr 
EN'€sr 
anoK a•n6yuo) 
pauuon 
sdno•ô 
saupd!d 
sdOAao ai nzv 
5

Once you select, it by default generate pipeline configuration in yaml which contains all the required task/steps to download dependent nuget package, compile code, test your project code in asp.net core, refer below :

Connect 
New pipeline 
u Select 
Configure 
Review your pipeline YAML 
TestProject1 / azure-pipelines-l.yml' —I' 
Variables 
Save and run 
Show assistant 
4 
ASP.NET core, (.NET Framework) 
Build and test ASP .NET projects targeting the full - .NET Framework. 
Add steps that publish symbols, save artifacts, and/ more: 
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core 
trigger : 
omaster 
pool : 
vmlmage : 
variables : 
solution: 
' windows-latest 
. s Inv 
buildplatform: 'Any 'CPU' 
buildConfiguration: 'Release ' 
steps : 
Settings 
'task: 
'task: 
NuGetTooIInstaIIer@I 
NuGetCommand@2 
inputs:

Addition to this, we need to add one more - task to publish the code(called artifacts), so that on successful pipeline run, it will publish your code as artifact which you can verify/download/push-to-your-any-server manually or using CD(release pipeline).
So to add publish - task to this yaml pipeline configuration, go the end of this file (keep curser there) and then from right side (show assistant option) search for publish artifact task and select that and configure:

Connect 
New pipeline 
Review your pipeline YAML 
TestProject1 / azure-pipelines-l.yml' —I' 
O/p:sk 
Select 
u Configure 
Tasks 
Variables 
publish artifacd 
Save and run 
inputs: 
restoreSoIution: 
'task: VSBuiId@I 
inputs: 
'$(solution) 
solution: 
'$(solution) 
msbuiIdArgs: 
' / /p : WebPubIishMethod=Package /p : PackageAsSingIeFiIe=true 
platform: '$(buiIdPIatform) 
configuration: '$(buiIdConfiguration) 
'task: L VSTest@2 
inputs: 
platform: '$(buiIdPIatform) 
configuration: '$(buiIdConfiguration) 
Copy and Publish Build Artifacts 
copy Fie 
Index sources and publish symbols 
Index your source code publTst symbols to 
npm 
Anst&l' publTst rpm or an npm 
Publish build artifacts 
to Azure PTpeIines or Wit... 
Publish Pipeline Artifacts

Put artifact name and add. Here I also changed the path(so if you refer build task in your yaml file that contains this path and I used same here to publish artifacts):

Connect 
New pipeline 
u Select 
u Configure 
Review your pipeline YAML 
TestProject1 / azure-pipelines-l.yml' —I' 
Settings 
.s=true /p:DepIoyIisAppP 
Settings 
Variables 
Save and run 
Publish Pipeline Artifacts C) 
File or directory path' O 
S(buiId.artifactStagingDirectonj) 
Artifact neme O 
test-projecN1-aäifacts 
Artifact publish location * 
Azure Pipelines 
o

 

If you want to update again any task, you can click on setting and it will open again the visual (task assistant option):

Connect 
New pipeline 
Select 
u Configure 
Review your pipeline YAML 
TestProject1 / azure-pipelines-l.yml' —I' 
msbuiIdArgs : 
'p: Deployonauild=true 
'platform: '$(buiIdPIatform) 
configuration: ' $(buiIdConfiguration) 
Itask: 'VSTest@2 
inputs : 
'platform: '$(buiIdPIatform) ' 
configuration: ' $(buiIdConfiguration) 
Settings 
•task: PublishPipeIineArtifact@I 
inputs: 
targetPath: '$(build . artifactStagingDirectoy) ' 
artifact: 
' test-projectl -artifacts ' 
publishLocation: ' pipeline 
Variables 
Save and run 
/ p : Pa ckageAsSingIeF ile 
=true 
/p:Sk 
•e Publish Pipeline Artifacts C) 
File or directory path' O 
Artifact neme O 
test-projectl-aftifacts 
Artifact publish location * 
Azure Pipelines 
About this task 
o 
Add

Now save your pipeline and post that you can start seeing your pipeline:

Connect 
New pipeline 
u Select 
u Configure 
Review your pipeline YAML 
TestProject1 / azure-pipelines-l.yml' —I' 
Variables 
Tasks 
p Search tasks 
.NET core 
Save and run 
4 
*ASP.NET core, (.NET Framework) 
Build and test ASP .NET projects targeting the full - .NET Framework. 
Add steps that publish symbols, save artifacts, and/ more: 
https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core 
trigger : 
omaster 
Suit, test: or applicetio... 
Android signing

 

https://dev.azure.com/sarajeevraj/TestPraject1/_build?view=folders 
Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Library' 
sarejeevrej 
4. 
TestPraject 1 
Pipelines 
Search 
Pipelines 
Recent All Runs 
All pipelines 
Name 
C) TestProject1 (1) Na runs yet 
C) estProject1-0Jl)-ASP.NET core-Cl No runs yet 
estProject1 *20210605.1 • update azure-pipelines.yml for arctifects 
Not syncing 
New pipeline 
Y Filter pipelines 
New folder 
Run pipeline 
Menage security 
Rename/move 
Delete

 

Now for test, run your new pipeline manually and verify your published artifacts:

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Libran,' 
Task groups 
Deployment groups 
Test Plans 
sarejeevrej 
4. 
TestPraject1 / 
Pipelines 
TestProject1 (1) 
Get started end run this pipeline for the first 
Run pipeline 
Run pipeline 
Select parameters below and manually run the pipeline 
TestProject1 (1) 
Runs Branches Analytics 
Branch/teg 
master 
Select the commit, or teg 
Advanced options 
Variables 
This pipeline has no variables 
Stages to run 
as configured 
Resources 
use latest version of all rescurces 
C) Enable system diagnostics 
Cancel

 

While pipeline running, you can validate the full job status:

Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Library' 
Task groups 
Deployment groups 
4. 
O #20210612.1 Set up Cl with Azure Pipelines 
on Test?rojectl (1) 
Summary 
Manually run byo Rajeev 
Repository end version 
TestProject1 
P master 16dcce6 
Jobs 
Name 
O Job 
Time started end elapsed 
Just now 
Cancel 
View 4 changes 
Tests end coverage 
Get started 
Releted 
O O work items 
O artifacts 
Du ration 
Queued

 

sarejeevrej 
TestPraject 1 
Pipelines 
Jobs in run #20210612.1 
Test?rcjectl (1) 
Jobs 
@ Job 
Testprojectl (1) / 20210612.1 
NuGetCommand 
Task 
P Search 
run a NLßet co—nd. 
4 
le 
11 
12 
13 
Is 
16 
18 
Desc 
Versim 
Help 
: Restore, pack, or push packages, 
: 2.179.e 
: Microsoft Corporatim 
rosoft. 
NuGet.org 
O 
O 
Initialize job 
Checkout TestProject1 
NuGetToollnsteller 
NuGetCommand 
vssuild 
VSTest 
Publish PipelineArtifect 
Post-job: Checkout TestPr... 
"C: 'Program Files (x86)/hicrosoft Visual Studio/2ø19/Enterprise/MSBuiId/Current/Bin/•sbuiId.exe" 
sysrewsscwæcncrq exists true 
sysrewsscwæcncrq exists true 
6søe1 
Active page: 
*tected NL&t version 5.9.1.11 / 
sysrewsscwæcncrq exists true 
sources Add -Nonmteractive -Name NuGetOrg 
Package source with added successfully. 
restore

 

Once pipeline is completed, you can see the published artifacts. To know all the history of pipeline run, go to pipeline you are looking for and there you will find all the run history and then click on specific history which you want to check and there you will find the publish artifacts:

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
sarejeevrej 
4. 
TestPraject 1 
Pipelines 
TestProject1 (1) 
P Search 
TestProject1 (1) 
Runs Branches Analytics 
Description 
#20210612.1 Set up Cl with Azure Pipelines 
A Manually triggered for master 
16tcce6 
Stages 
e

 

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Library' 
Task groups 
Deployment groups 
Test Plans 
sarejeevrej / TestPraject1 
4. 
Pipelines 
/ Testprojectl (1) / 20210612.1 
#20210612.1 Set up Cl with Azure Pipelines 
an Test?rcjectl (1) 
O This build will be retained forever by master (Branch) 
Summary Tests 
Manually run byo Rajeev 
Repository end version 
O TestProject1 
P master 16dcce6 
Jobs 
Name 
e Job 
Time started end elapsed 
Today at 2:38 PM 
@ 1m27s 
P Search 
Releted 
O work items 
1 publ•shed 
Success 
View 
Tests end coverage 
Get started 
Du ration 
@ 1m 16s

 

Azu re DevOps 
Test Project 1 
Boards 
Pipelines 
Pipelines 
Environments 
Releases 
Library' 
Task groups 
Deployment groups 
sarejeevrej 
4. 
TestPraject 1 
Pipelines 
TestProject1 (1) 
20210612.1 
Published artifacts 
Artifacts 
Published 
Name 
v test-projectl-artifacts 
Test1App.WebParameters.xml 
Test1App.Web.SetPerameters.xml 
Test1App.Web.SourceMenifest.xml 
Test1App.Web.deplay-readme.txt 
Test1App.Web.deplay.cmd 
WebApp zip 
P Search 
331 B 
147 B 
157B 
15 KB

 

Now, I want to trigger my CI pipiline automatically on code commit/push to my Azure repository app created and to do that, go to pipline you just created and navigate to trigger tab, and change the trigger option:

Azure DevOps 
TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
Library 
Task groups 
Deployment groups 
Test Plzns 
•rte cts 
Test?rojectl 
Seercfn 
TestProject1 (1) 
YAML Variables Triggers 
History 
Continuous integration 
TestProject 1 
Scheduled 
Build completion 
SuilS wen build 
Save & queue 
Discard 
Add 
Add 
Summery 
2 Queue 
Test Project 1 
C".'erride the YAML continuous integration trigger from here 
C) irtegrztTor 
@ Engle contTnucus Integrzticn 
cfnznges while build is in progress 
Branch filters 
Type 
Include 
+ Add 
Path filters 
+ Add 
Branch specification 
p master

If you are in YAML view then, to get trigger tab: edit you pipeline and then either you will find trigger tab on same screen, otherwise choose this option from three dot(…):

Azure DevOps 
TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
serajeevrsj / Test?rojectl 
TestProject1 (1) 
Builds 
Test Project I 
$9 
Seercfn 
Tasks 
master v Testprojectl / azure-pipelines-I .yml 
# ASP.NET core (.NET Framework) 
#BuiId and*est ASP .NET fulv .NET Franework. 
#Add steps that save build artifacts, and more: 
https:/'docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core 
Search ta: 
.NET cc 
Suilc( 
Variables 
Settings 
Validate 
Downlozd tull YAMI_ 
Triggers 
tr igger: 
master 
pool: 
vnlmage: 
'uindous-latest 
Android signing 
Sign Sign 
uilS Ant

So now, whenever you push/commit code to master branch, your pipeline will start automatically.

Azure DevOps 
TestP rojectl 
Overview 
Boards 
Repos 
Pipelines 
Pipelines 
Environments 
Releases 
serajeevrsj / Test?rojectl 
Pipelines 
Recent ALI Runs 
Recently run pipelines 
TestProjectI (I) 
Test Projectl 
for o master 
*20210'EOS.I • Update azure-pipelines.yml for arctitzcts 
A for o master 
Seercfn 
Y Filter pi; 
ta Jun;

 

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