Implementing the Build Pipeline Using Deployment Tasks

Implementing the Build Pipeline Using Deployment Tasks

In the previous post, we created a pipeline using YAML and learned how to create jobs and tasks in YAML format, as well as how to export and import a build pipeline. This post will focus on creating a pipeline using standard tasks. By the end, you will understand how to create a build pipeline for web application development, including Node.js, .NET Core, Docker, and Microsoft SQL Server, both on-premises and in Azure.

We will cover the following topics:

- Working with Node.js and Node Package Manager (NPM) tasks

- Working with .NET Core CLI tasks

- Working with Docker tasks

- Working with SQL Server deployment tasks

Let's begin by learning how to create a pipeline using Node.js and NPM tasks.

Working with Node.js and NPM tasks

To build and deploy Node.js applications, you need to use Node.js and NPM commands. Azure pipelines provide many predefined tasks to facilitate this process. Here's how to create a pipeline using Node.js and NPM tasks:

1. Log in to the Azure DevOps portal.

2. Select your organization.

3. Navigate to the Pipelines page.

4. Click on "New pipeline."

New Pipeline

2. Select Azure Repos Git, which is a source code repository for this demo:

Selecting Azure Repos Git

3. Select the PacktAzureDevOps repository that we created in the previous week post

Selecting a repository

4. Click on Show more:

Showing more tasks

5. Select the Node.js option:

Selecting Node.js

6. You can rename the default filename, azure-pipelines-1.yml, by clicking on it and changing it to node.yml:

Editing the name of the file

7. Click on Save and run | Save:

Saving a pipeline file

After selecting a template for Node.js and NPM tasks, We can modify the default NPM command to suit your Azure pipeline requirements, including specifying the version of Node.js you need. The following section will demonstrate how to create tasks for .NET Core.

Working with .NET Core CLI tasks

To build and deploy .NET applications, you need to use .NET Core CLI commands. Azure pipelines offer many predefined tasks for this purpose. Follow these steps to create a pipeline using .NET Core CLI tasks:

1. Follow steps 1 to 3 from the previous section on Node.js and NPM tasks.

2. Select "Starter pipeline."

Selecting the Starter Pipeline option

3. Rename the file from the default name to make it easier to understand what the YAML file is for:

Renaming a pipeline file

4. Select the Use .NET Core task and click Add:

Selecting the Use .NET Core task

5. Update the version property to use .NET 6

Updating the .NET version

6. Select the .NET Core task and click on Add:

Selecting the .NET Core task

7. Review the two predefined .NET tasks:

- UseDotNet@2 is used to install .NET compiler version 6.0.x.

- DotNetCoreCLI@2 is the .NET command to run a specific command, such as the build command.

These tasks are shown in the following screenshot:

A view of the .NET Core build task

After creating a starter task for the .NET CLI command, you can further customize your tasks using the DotNetCoreCLI@2 command. This command specifies the build process for your .NET application, converting source code into .NET binary files. The next section will demonstrate how to work with Docker tasks for containerized applications.

Working with Docker tasks

To build and deploy cloud-native applications, you need to use Docker commands. Azure pipelines offer many predefined tasks for this purpose. Follow these steps to create a pipeline using Docker tasks:

1. Follow steps 1 to 4 from the previous section on .NET Core CLI tasks.

2. Rename the file for the Docker pipeline:

Renaming the file

3. Select the Docker CLI installer task, click on Add, and update DockerInstaller@0:

- task: DockerInstaller@0

inputs: docker version: '17.09.0-ce'

The following screenshot shows you how to add a Docker CLI installer task and fill in the details on this task:

Adding a Docker CLI installer task

4. Select the Docker task and click on Add, and you will see the following code. This is the Docker task to build and push images in one task:

- task: Docker@2

inputs: ommand: 'buildAndPush'

Dockerfile: '**/Dockerfile'

The following screenshot shows you how to add a Docker task and fill in the details:

Adding a Docker task

5. Next, select the Command line task and click Add. Update the command line, as shown in the following code snippet:

- task: CmdLine@2

inputs:

script: |

docker login <docker hub url> -u <your username> -p <your

password>

docker push <your repository>:<your tag>

The following screenshot shows you how to add a Command line task and fill in the details:


Adding a Docker task

After running this pipeline, you will see the Docker image on your Docker Hub.

Working with SQL Server deployment tasks

To build and deploy SQL Server applications, you need to use SQL Server commands. Azure Pipelines provide several tasks for this purpose. Follow these steps to create a pipeline using SQL Server deployment tasks:

1. Follow steps 1 to 4 from the "Working with .NET Core CLI tasks" section.

2. Rename the file as shown in the following screenshot:

Implementing the Build Pipeline Using Deployment Tasks

Renaming the File

3. Search for SQL Server database, select the SQL Server database deploy task, and enter the following:

- task: SqlDacpacDeploymentOnMachineGroup@0

inputs:

TaskType: 'sqlQuery'

SqlFile: 'migrate.sql'

ExecuteInTransaction: true

ServerName: 'localhost'

DatabaseName: 'your_database'

AuthScheme: 'sqlServerAuthentication'

SqlUsername: 'your_username'

SqlPassword: 'your_password'

Let's explore each property in detail:

  • TaskType: This can be dacpac, sqlQuery, or sqlInline:

  • dacpac indicates that the task will execute SQL commands from a dacpac file.
  • sqlQuery indicates that the task will execute SQL commands (e.g., SELECT, UPDATE, INSERT, DELETE) from a SQL file.
  • sqlInline: This indicates that the task will execute SQL directly as a non-transactional operation in the SQL file.
  • SqlFile: This specifies the full path and name of the SQL file.
  • ExecuteInTransaction: When set to true, the task executes the SQL commands within a transaction scope.
  • ServerName: This should be the name or IP address of the database server.
  • DatabaseName: Specifies the name of the database where the SQL commands will be executed.
  • AuthScheme: This can be sqlServerAuthentication, which uses authentication from SQL Server, or windowsAuthentication, which uses authentication from Windows.
  • SqlUsername: This is the username for SQL Server authentication.
  • SqlPassword: This is the password associated with the SQL Server username for authentication.

The following screenshot shows you how to add the SQL Data-Tier Application Package (DACPAC) deployment task and fill in the details:

Adding the SQL Server database deploy task

Once you've created a SQL Server database deploy task, you can proceed to customize it further. For example, you can specify the ServerName parameter, which indicates the hostname or server name of the SQL Server that the task should connect to. After making these customizations, remember to save the pipeline file.

This post has guided you through creating build and release pipelines using standard NPM, the .NET Core CLI, Docker, and SQL Server deployment tasks. These predefined tasks are widely used for building and deploying Node.js and .NET applications. They streamline the process for developers, saving time that would otherwise be spent manually configuring commands in pipelines for these applications.        

Microsoft Azure DevOps Microsoft Learn Microsoft Azure











:









要查看或添加评论,请登录

Ankit Ranjan (DevOps Engineer)的更多文章

  • What is Azure Pipelines?

    What is Azure Pipelines?

    Azure Pipelines Benefits of Azure Pipelines Azure Pipelines offers a fast, reliable, and secure way to automate the…

  • Installing Docker on Windows 11 using WSL 2: A Step-by-Step Guide

    Installing Docker on Windows 11 using WSL 2: A Step-by-Step Guide

    Docker has become a crucial tool for developers, enabling seamless and portable application deployment. Prerequisites…

  • Safeguard Your Azure Route Server with Azure DDoS Protection

    Safeguard Your Azure Route Server with Azure DDoS Protection

    This guide walks you through securing your Azure Route Server by integrating it with Azure DDoS Protection in a virtual…

  • Protect your public load balancer with Azure DDoS Protection

    Protect your public load balancer with Azure DDoS Protection

    Azure DDoS Protection provides advanced mitigation features like adaptive tuning, attack alert notifications, and…

  • Create a public load balancer with an IP-based backend

    Create a public load balancer with an IP-based backend

    This Edition will teach us how to create a public load balancer with an IP-based backend pool. Traditionally, an Azure…

  • Load Balancer and its Different Types

    Load Balancer and its Different Types

    Global Load Balancer The Azure Standard Load Balancer enables cross-region load balancing, providing geo-redundant high…

  • Inbound NAT Rule

    Inbound NAT Rule

    Inbound NAT rules enable connections to virtual machines (VMs) in an Azure virtual network using a public IP address…

  • Azure Availability Set

    Azure Availability Set

    As part of a high-availability deployment, virtual machines are typically organized into multiple availability sets to…

    8 条评论
  • Azure Load Balancer (Part 2)

    Azure Load Balancer (Part 2)

    What is Azure Front Door Azure Front Door helps you deliver content, files, apps, and APIs with better availability…

  • Azure Load Balancer (Part-1)

    Azure Load Balancer (Part-1)

    Load balancing involves the efficient distribution of incoming network traffic across multiple backend servers or…

社区洞察

其他会员也浏览了