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."

Article content
New Pipeline

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

Article content
Selecting Azure Repos Git

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

Article content
Selecting a repository

4. Click on Show more:

Article content
Showing more tasks

5. Select the Node.js option:

Article content
Selecting Node.js

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

Article content
Editing the name of the file

7. Click on Save and run | Save:

Article content
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."

Article content
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:

Article content
Renaming a pipeline file

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

Article content
Selecting the Use .NET Core task

5. Update the version property to use .NET 6

Article content
Updating the .NET version

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

Article content
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:

Article content
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:

Article content
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:

Article content
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:

Article content
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:


Article content
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

Article content
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:

Article content
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











:









To view or add a comment, sign in

Others also viewed

Explore topics