How to Deploy a React App to an Azure Windows VM Using Azure DevOps Release Pipeline

Step 1:

Create an Azure Virtual Machine and Install Internet Information Services (IIS) Manager on the VM, as shown below, and verify.

Do this inside your Azure Windows VM

1. Open PowerShell as Administrator.
2. Install IIS + Management Tools by running this

Install-WindowsFeature -name Web-Server -IncludeManagementTools

Screenshot – Do this inside your Azure Windows VM: 1. Open PowerShell as Administrator. 2. Install IIS + Management Tools by…
  1. Confirm IIS is installed:
  • Open a browser in your VM ? go to http://localhost

You should see the IIS Welcome Page

Screenshot – Do this inside your Azure Windows VM: You should see the IIS Welcome Page

Optional: Restart the IIS service (after installation)
iisreset

Step 2:

Inside the Azure VM, React application, push to Azure Repos or GitHub

git init  # If not already initialized
git remote add azure <azure-repo-url>
git add .
git commit -m "Your commit message"
git push azure master  # Or your branch name instead of master

STEP 3: Build and deploy the artifact file

Screenshot – Do this inside your Azure Windows VM: STEP 3: Build and deploy the artifact file
Screenshot – Do this inside your Azure Windows VM: STEP 3: Build and deploy the artifact file (2)

Past yaml code Here

trigger:
  - main  # Change this if your branch is different

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildDir: 'build'

stages:
  - stage: Build
    displayName: 'Build React App'
    jobs:
      - job: BuildJob
        displayName: 'Build Job'
        steps:
          - task: NodeTool@0
            inputs:
              versionSpec: '18.x'
            displayName: 'Install Node.js'

          - script: |
              npm install
              npm run build
            displayName: 'Install dependencies and build React app'

          - task: CopyFiles@2
            inputs:
              sourceFolder: '$(Build.SourcesDirectory)/$(buildDir)'
              contents: '**'
              targetFolder: '$(Build.ArtifactStagingDirectory)/reactapp'
            displayName: 'Copy build output to staging directory'

          - task: PublishBuildArtifacts@1
            inputs:
              PathtoPublish: '$(Build.ArtifactStagingDirectory)/reactapp'
              ArtifactName: 'reactapp'
              publishLocation: 'Container'
            displayName: 'Publish build artifacts'

Step 4: Go to Azure DevOps > Pipelines > Deployment Groups to create a new.

Screenshot – Step 4: Go to Azure DevOps > Pipelines > Deployment Groups to create a new.

Deployment group and copy the PowerShell script

Screenshot – Step 4: Go to Azure DevOps > Pipelines >…: Deployment group and copy the PowerShell script

Step 5: Go to VM > PowerShell> paste the script and run with default values.

Screenshot – Step 5: Go to VM > PowerShell> paste the script and run with default values.
Screenshot – Step 5: Go to VM > PowerShell> paste the script and run with default values. (2)

Once you successfully run the script in the VM, you will see the VM is online in Azure DevOps.

Screenshot – Step 5: Go to VM > PowerShell> paste the script…: Once you successfully run the script in the VM, you will see the VM is online…

Step 6: Go to Release pipelines > Click new pipeline Add an artifact  file

Screenshot – Step 6: Go to Release pipelines > Click new pipeline Add an artifact file

Select the IIS Website Deployment template.

Screenshot – Step 6: Go to Release pipelines > Click new…: Select the IIS Website Deployment template.

Select the deployment group you have created

Screenshot – Step 6: Go to Release pipelines > Click new…: Select the deployment group you have created

Check the action and physical path

Screenshot – Step 6: Go to Release pipelines > Click new…: Check the action and physical path

Make sure you have provided the correct path for the artifacts folder to deploy

Screenshot – Step 6: Go to Release pipelines > Click new…: Make sure you have provided the correct path for the artifacts folder to deploy

Step 7: Run the pipeline and check the output:

Screenshot – Step 7: Run the pipeline and check the output

Outputs:

Screenshot – Outputs

Get new Microsoft 365 and Azure guides from Azure365Pro first in Google.

Premnath
Premnath
I have been working as Cloud engineer in System Administration field in Microsoft Azure, Microsoft Office 365 / Exchange Servers / Endpoint Manager / Azure Active Directory (IAM) / PowerShell

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here