Search code examples
azure-devopscontinuous-deploymentazure-pipelines-release-pipelinehealth-monitoringazure-devops-pipelines

How do I perform health-check for on premises IIS app behind firewall using Azure DevOps release pipeline


What do I have?

I have already setup deployment of my ASP.NET Core app to my IIS. The IIS app itself is not visible from internet, because it is behind firewall.

Question

How can I ping my app from the server where it is running (so that it will perform HTTP GET to localhost) and report back to Azure DevOps? Ideally using existing Task

I could probably write some PowerShell, but I would really like to use exiting solution


Solution

  • As of this time, however, I'm afraid there isn't a built-in task can perfectly solve your question.

    There is an Invoke REST API task that can invoke HTTP APIs and parse the response. But this task can be used in only an agentlees job, in other words, you cannot use this task unless you set your firewall to allow access from Azure DevOps.

    Update: Using PowerShell task

    Prerequisites: You need to use self-hosted agent so that you can access your application within your firewall.

    The following is demonstrated using YAML pipeline. The steps for classic UI pipeline is roughly the same.

    If you just want to get the response body:

    Just use a Powershell task and send your web request:

    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          ...
          Invoke-RestMethod ...
    

    If you want to save the response body as a variable:

    Step 1. Set a variable:

    variables:
      result: null
    

    Step 2. Use the PowerShell task to send a HTTP request and update the variable:

    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          ...
          $response = Invoke-RestMethod ...
          Write-Host "##vso[task.setvariable variable=result;]$response"
    

    Step 3. Then the value of $($env:RESULT) is the response body of your web request, and you can use it in subsequent tasks.