Search code examples
powershellazureazure-git-deployment

Access Azure/Kudu Variables from PowerShell Post Deployment Action Hook


I'm deploying Azure app services with Git continuous deployment and using post deployment action hooks to log the deployment to a Slack channel. My action hooks are written as PowerShell scripts.

From within my PowerShell scripts how do I access Azure or Kudu environmental variables or app settings? It's clear how to do this via deploy.cmd but I'm having no luck from PowerShell.

Ideally I'd like to be able to access things like:

  • Azure app service name
  • Deployment slot name
  • Deployment source/target paths
  • App settings and/or connection strings

Solution

  • Ok figured this out, apparently all of the Azure environment variables available within your website app service are available to PowerShell scripts running as post deployment actions.

    To get the site name within PowerShell:

    $siteName = [environment]::GetEnvironmentVariable("WEBSITE_SITE_NAME");
    

    In addition to site name there are dozens of other Azure environment variables plus your app settings and connection strings.