Loading...

Azure Tips and Tricks - Set up an Azure Pipeline with Node.js

Azure Tips and Tricks - Set up an Azure Pipeline with Node.js

Set up an Azure Pipeline with Node.js

 

 

Build a Node.js application with Azure Pipelines

 

A great way to improve the quality of your application is to automatically build it whenever you make changes. This enables you and your team to see if the application still works and fix errors quickly. You can easily set up a build pipeline with Azure Pipelines, which is part of Azure DevOps.

 

In this post, we'll create an Azure Pipeline that builds and tests a Node.js application.

 

Prerequisites

 

If you want to follow along, you'll need the following:

 

Create an Azure Pipeline that builds and tests a Node.js application

 

Let's automate the build process of a Node.js app! For this example, we'll use an existing Node application from GitHub. Before we can start, we need to fork it:

  1. Go to https://github.com/MicrosoftDocs/pipelines-javascript and sign in with your GitHub account
  2. Click the Fork button at the top of the repository. This will fork the repository to your account so that we can use it in our pipeline

Now we'll create the pipeline to build and test the Node application:

  1. Go to the Azure DevOps portal and sign in
  2. Create a new project and click on it when you are done

 

manojsrinivas_0-1656024132245.png

 

(Azure DevOps project)

 

  1. In the "Welcome to the project!" pane, click on Pipelines to start creating a new Azure Pipeline. This will start a wizard
  2. First, we need to indicate where our code is. It is in GitHub, so select GitHub

 

manojsrinivas_1-1656024132299.png

 

(Code choices in the Azure Pipelines wizard)

 

  1. Next, you'll see a list of repositories in your GitHub account. Select the forked repository that contains the sample Node.js application a. You might have to authorize Azure DevOps to use the GitHub repository. If so, click Approve & Install
  2. In the next step, select Node.js to configure the pipeline for Node.js

manojsrinivas_2-1656024132330.png

 

(Configuration choices in the Azure Pipelines wizard)

 

  1. The next screen shows you the YAML code that defined the pipeline. You can learn more about YAML here. This code determines that node.js will be used and that the pipeline will perform a build. This code will only build the code and not execute any unit tests. Let's change that:


    a. In the script section of the YAML code, add the following to enable the pipeline to run the unit tests in the code:

    npm test

    b. Below the scripts section, add the following code to publish the test results to the build results:

    - task: PublishTestResults@2 inputs: testResultsFormat: 'JUnit' testResultsFiles: '**/TEST-*.xml'
     

manojsrinivas_3-1656024132281.png

 

(YAML code of the Azure Pipeline)

 

  1. Now click Save and run to save the pipeline and start it. The pipeline will now start building and testing the code. When it is done, you'll see the results like in the image below:

manojsrinivas_4-1656024132347.png

 

(Results of the Azure Pipeline)

 

  1. The build was successful! In the screen of the build results, you can click the Tests tab to see the results of the Unit Tests
  2. In the test result screen, you can see the Unit Tests that ran (which is only one test in this case), and what the result of the run was

 

manojsrinivas_5-1656024132314.png

 

(Test results of the Azure Pipeline)

 

That's it. We have set up a pipeline that automatically builds and tests the application when changes are made to it. From here, you can set up more pipelines, like a release pipeline, that takes the build result and deploys it to a server. You can learn more about that here.

 

Conclusion

 

Setting up a Continuous Integration (CI) process, which builds your code automatically, is one of the simplest ways to increase the quality of your applications. It is very easy to set up a CI pipeline with Azure Pipelines, regardless of the programming language that you use or where your code is. To learn more, create a trial account today and go and check it out

Published on:

Learn more
Azure Developer Community Blog articles
Azure Developer Community Blog articles

Azure Developer Community Blog articles

Share post:

Related posts

This Month in Azure Static Web Apps | 09/2024

    We are back with another edition of the Azure Static Web Apps Community! :party_popper:   September was yet another month ...

1 year ago

GitHub Copilot for Azure: 6 Must-Try Features

As developers, we are constantly seeking tools that streamline our workflows and boost productivity. … Enter GitHub Copilot for Azure, now in ...

1 year ago

Responsible AI Mitigation Layers

Generative AI is increasingly being used in various kinds of systems to augment humans and infuse intelligent behavior into existing and new a...

1 year ago

Streamline Your Azure Workflow: Introducing GitHub Copilot for Azure in VS Code

I'm excited to announce the public preview of GitHub Copilot for Azure - a new addition to your toolkit that seamlessly integrates with G...

1 year ago

Build Intelligent Apps Code-First with Prompty and Azure AI

      Building Generative AI applications can feel daunting for traditional app developers. What does the end-to-end applicati...

1 year ago

Certificación AI-900 (Fundamentos de IA) con Chicas en IA

La inteligencia artificial ha llegado para quedarse, ¡y más aún con la revolucionaria IA generativa! Para ayudar a los profesionales a especia...

1 year ago

Get certified with Learn Live GitHub series!

GitHub Universe is coming, and Microsoft and GitHub are partnering to offer a new special Learn Live series in Brazilian Portuguese, English a...

1 year ago

Certifícate con Learn Live GitHub en Español

Microsoft y GitHub se han unido para ofrecer una nueva serie especial de Learn Live en inglés y español: GitHub 2024. Del 10 al 24 de Octubre,...

1 year ago

Evaluating generative AI: Best practices for developers

As a developer working with generative AI, you've likely marveled at the impressive outputs your models can produce. But how do you ensure the...

1 year ago

Introducing Azure Product Retirement Livestreams

The Azure Retirements team, in collaboration with key partner groups, is excited t...

1 year ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.