Skip to main content

Command Palette

Search for a command to run...

Automating Node.js Builds with Azure DevOps Pipelines

Updated
2 min read
Automating Node.js Builds with Azure DevOps Pipelines

Challenge: Part 1 Continuous integration

Set up a new repository and CI pipeline using any code version provider The CI steps should be created. The pipeline should run the following steps:

  • Install dependencies npm install

  • Linter (ESLint) npm run lint

  • Formatter (Prettier) npm run prettier

  • Test (Jest) CI=true npm run test

  • Build npm run build

The pipeline should be successful. Please provide some pull requests to show pass or fail status in the CI pipeline.

Prerequisites

  • Azure Devops Account

Step 1: Create and clone the Repository

  1. Create New Project:

  2. Once inside your organization's Azure DevOps dashboard, click on the "New Project" button, usually at the top right or in the center of the screen.

  3. Configure Project Details:

  4. Project Name: Enter "DevOps Challenge" as the project name.

  5. Go to Repos -> Import Repository -> Clone URL: https://github.com/joaochiroli/Devops-Challenge

Step 2: Create and configure azure-pipelines.yml

  1. Create file azure-pipelines.yml

     trigger:
     - main
    
     pr:
       branches:
         include:
         -  main
    
     stages:
       - stage: BuildAndTest
         displayName: Build and Test Job
         pool:
           vmImage: 'ubuntu-latest'
         jobs:
         - job: Build
           displayName: 'Build and Test Job'
           steps:
           - checkout: self
             path: 'src'
             displayName: 'Checkout code'
    
           - task: UseNode@1
             inputs:
               version: '15.x'
             displayName: 'Install Node.js'
    
           - script: npm install
             workingDirectory: $(Build.SourcesDirectory)/assessment-cc-sre-kubernetes-sr-01/codebase/rdicidr-0.1.0
             displayName: 'Install dependencies'
    
           - script: npm run lint
             workingDirectory: $(Build.SourcesDirectory)/assessment-cc-sre-kubernetes-sr-01/codebase/rdicidr-0.1.0
             displayName: 'Linter (ESLint)'
    
           - script: npm install --save-dev prettier
             workingDirectory: $(Build.SourcesDirectory)/assessment-cc-sre-kubernetes-sr-01/codebase/rdicidr-0.1.0
             displayName: 'Install Formatter (Prettier)'
    
           - script: npm run prettier -- --write
             workingDirectory: $(Build.SourcesDirectory)/assessment-cc-sre-kubernetes-sr-01/codebase/rdicidr-0.1.0
             displayName: 'Format Code (Prettier)'
    
           - script: CI=true npm run test
             workingDirectory: $(Build.SourcesDirectory)/assessment-cc-sre-kubernetes-sr-01/codebase/rdicidr-0.1.0
             displayName: 'Test (Jest)'
    
           - script: npm run build
             workingDirectory: $(Build.SourcesDirectory)/assessment-cc-sre-kubernetes-sr-01/codebase/rdicidr-0.1.0
             displayName: 'Run Build'
    
  2. Commit and Save

  3. Explanations:

    1. I created trigger main and pr to start my pipeline. I use 1 stage to Build my application.

    2. Task: UseNode@1 → Define the Node.js version

    3. The other tasks do what the above steps ask, and the key to this build is to run it in the correct repository.

Step 3: Results

More from this blog

J

Joaochiroli

12 posts

Everything about Devops and SRE