Implementing the Build Pipeline Using Deployment Tasks
Ankit Ranjan (DevOps Engineer)
Actively Seeking Azure DevOps/Cloud Role | DevOps Engineer | Automating & Reducing Developer Toil | Modernising IAC like Jam on the Bread | Microsoft Certified: Azure Admin Associate | Certified Terraform Associate |
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."
2. Select Azure Repos Git, which is a source code repository for this demo:
3. Select the PacktAzureDevOps repository that we created in the previous week post
4. Click on Show more:
5. Select the Node.js option:
6. You can rename the default filename, azure-pipelines-1.yml, by clicking on it and changing it to node.yml:
7. Click on Save and run | Save:
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."
3. Rename the file from the default name to make it easier to understand what the YAML file is for:
4. Select the Use .NET Core task and click Add:
5. Update the version property to use .NET 6
6. Select the .NET Core task and click on Add:
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:
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:
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:
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:
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:
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
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:
The following screenshot shows you how to add the SQL Data-Tier Application Package (DACPAC) deployment task and fill in the details:
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
: