Got a weird issue publishing a PowerShell Function to a Function App. The Function App uses Windows consumption with a Y1 App Service Plan.
The Function uses 5 different Az Modules that exist in the Modules Directory as part of the Package:
- Az.Accounts
- Az.Resources
- Az.Compute
- Az.Sql
- Az.SqlVirtualMachine
The File structure looks like this:
wwwroot/
| - .funcignore
| - ahubReporter
| | - function.json
| | - readme.md
| | - run.ps1
| - host.json
| - Modules
| | - Az.Accounts
| | - Az.Compute
| | - Az.Resources
| | - Az.Sql
| | - Az.SqlVirtualMachine
| - profile.ps1
| - requirements.psd1
NOTE:
managedDependencyis not enabled and theAzModules are not download automatically. The Modules are included in the source under theModulesdirectory and published with the function
If the Function is published manually through vscode using the Azure Function Extension, the function works and runs perfectly.
However, If I publish the Function by either the Azure DevOps Task AzureFunctionApp@2 or Azure PowerShell Task AzurePowerShell@5 using the command Publish-AzWebApp, the function is published, but does not run and I get the following error:
The 'Get-AzLocation' command was found in the module 'Az.Resources', but the module could not be loaded. For more information, run 'Import-Module Az.Resources'.
The Azure DevOps Pipeline is configured to use a Windows Agent.
The Azure DevOps Task AzureFunctionApp@2 is:
- task: AzureFunctionApp@2
displayName: 'Publish Function | package'
inputs:
azureSubscription: ${{ parameters.customerServiceConnection }}
appType: functionApp
appName: $(functionName)
package: $(System.ArtifactsDirectory)/**/*.zip
deploymentMethod: 'runFromPackage' # <--- I've tried auto as well
The Azure DevOps Task AzurePowerShell@5 is:
- task: AzurePowerShell@5
displayName: 'Publish Function | azpwsh'
inputs:
azureSubscription: ${{ parameters.customerServiceConnection }}
ScriptType: 'InlineScript'
Inline: 'Publish-AzWebapp -ResourceGroupName $(functionAppRg) -Name $(functionName) -ArchivePath $(System.ArtifactsDirectory)/build$(Build.BuildId).zip -Force'
azurePowerShellVersion: 'LatestVersion'
pwsh: true
Thanks!




