🔥 If you are interested in live coding then follow me on Twitch for developing on Azure and more.
📺 Watch the video : How to 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.
If you want to follow along, you'll need the following:
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:
Now we'll create the pipeline to build and test the Node application:
(Azure DevOps project)
(Code choices in the Azure Pipelines wizard)
(Configuration choices in the Azure Pipelines wizard)
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:
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'
(YAML code of the Azure Pipeline)
(Results of the Azure Pipeline)
(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.
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. Go and check it out!