Search code examples
azureazure-devopsazure-web-app-serviceazure-pipelines

Azure Windows Web App Node customize strart up script


Using DevOps Pipelines and Artifacts + Azure Web App (Windows) -> I'm trying to deploy server + website on the same machine.

It currently looks like a default node server is running and just waiting for static site on wwwroot folder.

But is there a way to specify and tell azure with which node.js script it should start the server?

In this example : Node quickstart they just push an "app.js" to wwwroot folder and it works.... they give info about how to change port but in my case I want to stop that default process and start mine !

I want to run my own server.


Solution

  • I tried deploying node.js application in Azure Web app (Windows) > While using Azure app service deploy task I added the start up command to run nodejs App.js like below in my YAML pipeline and the deployment was successful, Refer below:-

    My YAML pipeline:-

    App Type selected as Windows:-

    enter image description here

    Add Start up command in the same task:-

    enter image description here

    trigger:
    - main
    
    variables:
    
      
      azureSubscription: 'xxxx-xxxx0-xxx25653'
    
      
      webAppName: 'valleywebapp628'
    
      
      environmentName: 'valleywebapp628'
    
     
      vmImageName: 'windows-latest'
    
    stages:
    - stage: Build
      displayName: Build stage
      jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: $(vmImageName)
    
        steps:
        - task: ArchiveFiles@2
          displayName: 'Archive files'
          inputs:
            rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
            includeRootFolder: false
            archiveType: zip
            archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
            replaceExistingArchive: true
    
        - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
          artifact: drop
        - task: PowerShell@2
          inputs:
             targetType: 'inline'
             script: '$env:servicePrincipalId '
       
    
    - stage: Deploy
      displayName: Deploy stage
      dependsOn: Build
      condition: succeeded()
      jobs:
      - deployment: Deploy
        displayName: Deploy
        environment: $(environmentName)
        pool:
          vmImage: $(vmImageName)
        strategy:
          runOnce:
            deploy:
              steps:
              - task: AzureRmWebAppDeployment@4
                displayName: 'Azure App Service Deploy: siliconwebapp655'
                inputs:
                  ConnectionType: 'AzureRM'
                  azureSubscription: '$(azureSubscription)'
                  appType: 'webApp'
                  WebAppName: '$(webAppName)'
                  packageForLinux: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
                  ScriptType: 'Inline Script'
                  InlineScript: |
                    npm install
                    npm run build --if-present
                  ConfigurationSettings: '-startup-file node App.js'
    

    Output:-

    enter image description here

    For Release pipeline you can add the startup command for Windows Web app like below:-

    enter image description here

    Configuration settings:-

    -startup-file node App.js
    

    enter image description here

    Reference:-

    javascript - How Do I Change The Startup command In An Azure Web App Without The Portal? - Stack Overflow By silent