How do I use PowerShell Core with the "Deploy an Azure App Service" Octopus step?

188 views Asked by At

I am deploying an app service with the built in 'Deploy an Azure App Service' step. It fails with this error:

The term 'Remove-WebConfigurationLock' is not recognized as the name of a cmdlet, function, script file, or operable program.

I have another project that is working and the logs show that it uses a different version of PowerShell. I am pretty sure the problem is that I can't pick PowerShell Core with this step. I don't know why the other one uses it.

When using the built in 'Deploy an Azure App Service' step, I don't have an option that allows me to use PowerShell Core.

When I run a basic PowerShell Script step, I do have the option of using PowerShell Core. I add it using the 'Configure Feature' button below.

enter image description here

There is no 'Configure Feature' button on the 'Deploy an Azure App Service' step.

How do I get the 'Deploy an Azure App Service' step to use PowerShell Core?

UPDATE:

Two projects that I created are using PowerShell core (PS7), but I didn't do anything to cause that (that I can find).

enter image description here

My newest project is using PowserShell Desktop (PS5).

enter image description here

The new project, that uses PS5, is using PS7 on an earlier step.

1

There are 1 answers

5
SiddheshDesai On

Updated :-

I have tried using Default Worker pool with Powershell set to Windows Desktop and the PS-version is also 5.1. My Powershell Script below worked successfully.

# Display PowerShell version

$PSVersionTable.PSVersion.ToString()

# Install the IIS Web Role
Install-WindowsFeature -Name Web-Server -IncludeManagementTools

# Import the WebAdministration module
Import-Module WebAdministration

# Specify the PSPath and Filter
$PSPath = 'IIS:\Sites\Default Web Site'
$Filter = 'system.webServer/security/authentication/anonymousAuthentication'

# Remove the Web configuration lock
Remove-WebConfigurationLock -PSPath $PSPath -Filter $Filter

# Restart IIS to apply changes
Restart-WebAppPool -Name 'DefaultAppPool'
iisreset /restart

Output:- Powershell Version - 5.1

enter image description here

Worker Pool - Default Worker Pool PowerShell Edition - Windows Powershell (Desktop)

enter image description here

AFAIK, Remove-WebConfigurationLock is a part of WebAdministration Module And WebAdministration Module only works for Windows Server 2022 with IIS web role installed. Refer this SO thread answer1 and SO thread answer2 on the same.

Also, As per the Octopus Configuration settings, Powershell Core is only supported in the Non Windows machine, Thus you need to check which Worker Pool you are using to run your release. And the Remove-WebConfigurationLock failed after selecting Powershell Core and Ubuntu worker too on my end, like below:-

enter image description here

enter image description here

As a workaround, You can create a dynamic Worker pool with Windows 2022 server image like below and install the IIS web role in the dynamic Worker pool. Then run your Powershell command. Refer below:-

enter image description here

And then select the above worker pool in your Powershell task and run the below command to first install IIS Web role and then run your command:-

enter image description here

Add below code in Inline Source code:-

# Install the IIS Web Role
Install-WindowsFeature -Name Web-Server -IncludeManagementTools

# Import the WebAdministration module
Import-Module WebAdministration

# Specify the PSPath and Filter
$PSPath = 'IIS:\Sites\Default Web Site'
$Filter = 'system.webServer/security/authentication/anonymousAuthentication'

# Remove the Web configuration lock
Remove-WebConfigurationLock -PSPath $PSPath -Filter $Filter

# Restart IIS to apply changes
Restart-WebAppPool -Name 'DefaultAppPool'
iisreset /restart

Output:-

enter image description here

Above code will also work with Windows- Desktop Powershell along with Powershell Core like above.

Now, After running this command you can use Windows Server Core 2022 worker pool in your Deploy an Azure Web App (Web Deploy) to deploy your package. But according to this official octopus Document on Deploying Azure Web App task. the Task does not contain any setting toi configure Powershell version. Azure web apps | Documentation and Support (octopus.com) . You need to raise a support request with Octopus to get that feature. Also, While creating your web app package, You can use the above method with WindowsAdministration package and then use it in the Deploy Azure Web app step.

enter image description here