Azure Web App - Get Deployment User

Octopus.AzurePowerShell exported 2021-09-17 by adamoctoclose belongs to ‘Azure’ category.

This step template will retrieve a set of deployment credentials for an Azure Web App.

It will create two Octopus sensitive output variables for use in other deployment or runbook steps. They will be named:

  • userName - the username from the provided deployment credentials.
  • userPwd - the password from the provided deployment credentials.

Required:

  • An azure account with permissions to retrieve deployment credentials for the named Azure Web App.
  • The Azure CLI (az) is required to run this script. If running on a worker or deployment target, ensure this is installed.

Notes:

  • Tested on Octopus 2021.2.
  • Tested with both Windows PowerShell and PowerShell Core on Linux.

Parameters

When steps based on the template are included in a project’s deployment process, the parameters below can be set.

Azure Web App name

AzWebApp.DeploymentCreds.AzWebAppName =

Provide the Azure Web App name.

Azure Resource Group

AzWebApp.DeploymentCreds.AzResourceGroup =

Provide Azure resource group.

Azure Account

AzWebApp.DeploymentCreds.AzAccount =

Provide Azure Account.

Deployment credential type

AzWebApp.DeploymentCreds.PublishCredentialType = MSDeploy

Choose type of Deployment credentials should be retrieved. Default is: MSDeploy

Available options are:

  • MSDeploy
  • FTP
  • ZipDeploy

Script body

Steps based on this template will execute the following PowerShell script.

$ErrorActionPreference = "Stop";
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$resourceGroupName = $OctopusParameters["AzWebApp.DeploymentCreds.AzResourceGroup"]
$WebAppName = $OctopusParameters["AzWebApp.DeploymentCreds.AzWebAppName"]
$PublishCredentialType = $OctopusParameters["AzWebApp.DeploymentCreds.PublishCredentialType"]
$StepName = $OctopusParameters["Octopus.Step.Name"]

# Validation
if ([string]::IsNullOrWhiteSpace($resourceGroupName)) {
    throw "Required parameter AzWebApp.DeploymentCreds.AzResourceGroup not specified"
}
if ([string]::IsNullOrWhiteSpace($WebAppName)) {
    throw "Required parameter AzWebApp.DeploymentCreds.AzWebAppName not specified"
}
if ([string]::IsNullOrWhiteSpace($PublishCredentialType)) {
    throw "Required parameter AzWebApp.DeploymentCreds.PublishCredentialType not specified"
}
    
Write-Verbose "Azure Resource Group Name: $resourceGroupName"
Write-Verbose "Azure Web App Name: $WebAppName"
Write-Verbose "Publish Credential Type: $PublishCredentialType"

Write-Host "Getting $PublishCredentialType publish profile deployment credentials..."

$profiles = az webapp deployment list-publishing-profiles --resource-group $resourceGroupName --name $WebAppName | ConvertFrom-Json | where { $_.publishMethod -ieq $PublishCredentialType } 

Set-OctopusVariable -name "userName" -value $profiles.userName -Sensitive
Write-Highlight "Created output variable: ##{Octopus.Action[$StepName].Output.userName}"
Set-OctopusVariable -name "userPWD" -value $profiles.userPWD -Sensitive
Write-Highlight "Created output variable: ##{Octopus.Action[$StepName].Output.userPWD}"

Write-Host "Output variables generated for deployment credentials!"

Provided under the Apache License version 2.0.

Report an issue

To use this template in Octopus Deploy, copy the JSON below and paste it into the Library → Step templates → Import dialog.

{
  "Id": "f87564d3-50e0-4265-8ed7-d95e3e21f869",
  "Name": "Azure Web App - Get Deployment User",
  "Description": "This step template will retrieve a set of [deployment credentials](https://docs.microsoft.com/en-gb/azure/app-service/deploy-configure-credentials) for an Azure Web App.\n\nIt will create two Octopus [sensitive output variables](https://octopus.com/docs/projects/variables/output-variables#sensitive-output-variables) for use in other deployment or runbook steps. They will be named:\n\n- `userName` - the username from the provided deployment credentials.\n- `userPwd` - the password from the provided deployment credentials.\n\n**Required:** \n- An azure account with permissions to retrieve deployment credentials for the named Azure Web App.\n- The Azure CLI (`az`) is required to run this script. If running on a worker or deployment target, ensure this is installed.\n\nNotes:\n\n- Tested on Octopus `2021.2`.\n- Tested with both Windows PowerShell and PowerShell Core on Linux.",
  "Version": 1,
  "ExportedAt": "2021-09-17T17:13:19.362Z",
  "ActionType": "Octopus.AzurePowerShell",
  "Author": "adamoctoclose",
  "Packages": [],
  "Parameters": [
    {
      "Id": "7f36b854-6cc8-4a64-a7b4-c3110044cd4b",
      "Name": "AzWebApp.DeploymentCreds.AzWebAppName",
      "Label": "Azure Web App name",
      "HelpText": "Provide the Azure Web App name.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "41c6ca57-2078-4cbb-8e92-26c2207a3ef7",
      "Name": "AzWebApp.DeploymentCreds.AzResourceGroup",
      "Label": "Azure Resource Group",
      "HelpText": "Provide Azure resource group.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "SingleLineText"
      }
    },
    {
      "Id": "149ef6c1-716c-4738-9985-ea47e5fc6e9b",
      "Name": "AzWebApp.DeploymentCreds.AzAccount",
      "Label": "Azure Account",
      "HelpText": "Provide Azure Account.",
      "DefaultValue": "",
      "DisplaySettings": {
        "Octopus.ControlType": "AzureAccount"
      }
    },
    {
      "Id": "9ac94483-5e3b-49b3-9014-eb4875b95798",
      "Name": "AzWebApp.DeploymentCreds.PublishCredentialType",
      "Label": "Deployment credential type",
      "HelpText": "Choose type of Deployment credentials should be retrieved. Default is: `MSDeploy`\n\nAvailable options are:\n\n- `MSDeploy`\n- `FTP`\n- `ZipDeploy`",
      "DefaultValue": "MSDeploy",
      "DisplaySettings": {
        "Octopus.ControlType": "Select",
        "Octopus.SelectOptions": "MSDeploy|MSDeploy\nFTP|FTP\nZipDeploy|ZipDeploy"
      }
    }
  ],
  "Properties": {
    "Octopus.Action.Script.ScriptSource": "Inline",
    "Octopus.Action.Script.Syntax": "PowerShell",
    "Octopus.Action.Script.ScriptBody": "$ErrorActionPreference = \"Stop\";\n[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12\n\n$resourceGroupName = $OctopusParameters[\"AzWebApp.DeploymentCreds.AzResourceGroup\"]\n$WebAppName = $OctopusParameters[\"AzWebApp.DeploymentCreds.AzWebAppName\"]\n$PublishCredentialType = $OctopusParameters[\"AzWebApp.DeploymentCreds.PublishCredentialType\"]\n$StepName = $OctopusParameters[\"Octopus.Step.Name\"]\n\n# Validation\nif ([string]::IsNullOrWhiteSpace($resourceGroupName)) {\n    throw \"Required parameter AzWebApp.DeploymentCreds.AzResourceGroup not specified\"\n}\nif ([string]::IsNullOrWhiteSpace($WebAppName)) {\n    throw \"Required parameter AzWebApp.DeploymentCreds.AzWebAppName not specified\"\n}\nif ([string]::IsNullOrWhiteSpace($PublishCredentialType)) {\n    throw \"Required parameter AzWebApp.DeploymentCreds.PublishCredentialType not specified\"\n}\n    \nWrite-Verbose \"Azure Resource Group Name: $resourceGroupName\"\nWrite-Verbose \"Azure Web App Name: $WebAppName\"\nWrite-Verbose \"Publish Credential Type: $PublishCredentialType\"\n\nWrite-Host \"Getting $PublishCredentialType publish profile deployment credentials...\"\n\n$profiles = az webapp deployment list-publishing-profiles --resource-group $resourceGroupName --name $WebAppName | ConvertFrom-Json | where { $_.publishMethod -ieq $PublishCredentialType } \n\nSet-OctopusVariable -name \"userName\" -value $profiles.userName -Sensitive\nWrite-Highlight \"Created output variable: ##{Octopus.Action[$StepName].Output.userName}\"\nSet-OctopusVariable -name \"userPWD\" -value $profiles.userPWD -Sensitive\nWrite-Highlight \"Created output variable: ##{Octopus.Action[$StepName].Output.userPWD}\"\n\nWrite-Host \"Output variables generated for deployment credentials!\"",
    "Octopus.Action.Azure.AccountId": "#{AzWebApp.DeploymentCreds.AzAccount}",
    "OctopusUseBundledTooling": "False"
  },
  "Category": "Azure",
  "HistoryUrl": "https://github.com/OctopusDeploy/Library/commits/master/step-templates//opt/buildagent/work/75443764cd38076d/step-templates/azure-web-app-get-deployment-user.json",
  "Website": "/step-templates/f87564d3-50e0-4265-8ed7-d95e3e21f869",
  "Logo": "iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRF////AHjXf7vrv931QJrh7/f8EIDaIIncMJHfYKvmz+b3n8zw3+76j8Ttr9XycLPpUKLkkKvYFAAABGZJREFUeNrsnNmCqjoQRc1MEiD8/9cer7Yt2KBJZQC8ez07sKlKTQlcLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAzoUSnt8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/Sj90ucPRc/d/Bxxj+dXSpCayen32D+hLi16MsIV8gfCXrYp6ySsiJKRUF0XXiLpVbFU+fNv4r7mOwhFsX4ZdwpSi1DYs2jb6ebZ9788cblTzMrYhu7sf/17IFdtuviJ2ioHA6pMHkoH4CLUeMBU7iGkxuM/YgcdderF9ibRdc7O982F1HpYhjfWUe+x5a6pjop9iNLfoePvlsdZdTSMwfxSmTY20Q0eHnUNzga1edeNmmqbg18aMVR1L9vwSXHF9TfIWBxpKLs2hj3eQeBC0USvp2HHF3eIkRdhFOd6ER8AAAAAAAAAAAAAAAAAAAAAAAAAAAAA/I/4J8AAo/80BciBec4AAAAASUVORK5CYII=",
  "$Meta": {
    "Type": "ActionTemplate"
  }
}

History

Page updated on Friday, September 17, 2021