P M A J E W S K I

Please Wait For Loading

Azure DevOps Pipeline in practice - Software Developer's Tour

    You Are Currently Here!
  • Home
  • TutorialsAzure DevOps Pipeline in practice
22-01-14-School-backgrounds-similars 4

Azure DevOps Pipeline in practice

What is Pipeline?

Pipeline is a solution that automatically build, test and deploy an application. We can split Pipeline to (CI) and (CD) Pipelines.

CI – Continous Integration

CD – Continous Delivery/Deployment

CI – helps maintain code quality by catching errors early in the development process.

CD – streamlines the process of delivering code changes to production environments efficiently and reliably.

Use it in practice!

Today, I’ll show you how to use Azure DevOps Pipeline to deploy your application.

To follow this tutorial, go to Azure DevOps and create a new project.

azure_pipeline dashboard

I created a new organization named “pawelmajewskiblog” and a project named “Pipeline example“.

Now, let’s create a sample WebAPI application that we want to deploy using Azure Pipelines.

[WebApiProject - Minimal API] Program.cs

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();

var startDate = DateTime.Now;
var pipelineVariable = Environment.GetEnvironmentVariable("pipeline_variable");

app.MapGet("/", () =>
{
    return new { startDate, pipelineVariable };
})
.WithName("GetVersion")
.WithOpenApi();

app.Run();

This application contains one endpoint named GetVersion, which returns the start date of the application (startData) and the pipeline variable (pipelineVariable) that we will set in the pipeline.

 

Localhost response is presented below.

Push code to the repository

When our repository is ready, we can go to the next step.

Create first pipeline

Go to the

azure_pipeline_create

And click “Create Pipeline”.

Select your repository, I’ll choose “Azure Repos Git”

Use the script for pipeline presented below

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
  displayName: 'Install .NET Core SDK'
  inputs:
    version: 8.x
    
- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
  displayName: 'dotnet restore $(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'
  displayName: 'dotnet build $(buildConfiguration)'

When you save this pipeline configuration file, then pipeline runs automatically for the first time.

pipeline queued
pipeline in progress
pipeline success last step
pipeline branch success
pipeline list success

When the pipeline finishes its work, you will be notified by email.

build success

We’ll also receive an email when the build fails.

build failed
build canceled

leave a comment