I’ve encountered challenges deploying my PowerShell code from GitHub to an Azure Function (consumption plan windows). The function has been deployed with Terraform and GitHub, and I aim to automate the entire deployment process through GitHub rather than locally on my machine.
The PowerShell code, located in run.ps1and other project files, needs deployment to the Azure Function. Although my workflow file completes successfully, it appears that my function is not receiving the relevant code and is empty. Comparing my function project’s directory structure in VS Code to the PowerShell developer reference, there seems to be a difference.
My project’s directory structure:
.packaged-functionsrules-backup-function
.packaged-functionsrules-backup-functionanalytical-rules-backup-function
.packaged-functionsrules-backup-function.funcignore
.packaged-functionsrules-backup-function.gitignore
.packaged-functionsrules-backup-functionhost.json
.packaged-functionsrules-backup-functionlocal.settings.json
.packaged-functionsrules-backup-functionprofile.ps1
.packaged-functionsrules-backup-functionrequirements.psd1
.packaged-functionsrules-backup-functionanalytical-rules-backup-functionfunction.json
.packaged-functionsrules-backup-functionanalytical-rules-backup-functionrun.ps1
.packaged-functionsrules-backup-functionanalytical-rules-backup-functionsample.dat
Documentation powershell function directory structure:
My GitHub workflow file:
name: Deploy Azure Function
on: workflow_dispatch
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Zip folder
run: |
cd packaged-functions/rules-backup-function
zip -r ../../output.zip .
shell: bash
- name: Upload zip file
uses: actions/upload-artifact@v2
with:
name: function-zip
path: output.zip
deploy-azure-function:
runs-on: windows-latest
needs: build-and-deploy
environment: dev
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v3
- name: 'Download zip file'
uses: actions/download-artifact@v2
with:
name: function-zip
path: .
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
with:
app-name: ${{ secrets.AZURE_FUNCTIONAPP_NAME }}
package: .
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
In my Azure functions there is no "function" listed:
I’ve consulted the following documentation, but the issue persists:
https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push
Edit 1:
I have deployed for a second time without zipping the code as a seperate step:
Workflow File:
name: Deploy PowerShell project to Azure Function App
on: workflow_dispatch
# [push]
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: 'packaged-functionsrules-backup-function' # set this to the path to your function app project, defaults to the repository root
jobs:
build-and-deploy:
runs-on: windows-latest
environment: dev
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v3
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ secrets.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
However I am getting new errrors now visible in the Azure Function, in the portal:
"Microsoft.Azure.WebJobs.Script: Did not find functions with language [dotnet]."
Runtime version: Error
And, like before the functions tab with my functions code is not visible:
This leads me to believe the configuration of my azure function is incorrect:
Or the configuration with terraform when deploying the function is incorrect:
resource "azurerm_service_plan" "analytical-rules-backup" {
name = "analytical-rules-backup-plan"
resource_group_name = module.environment.resource_group_name
location = module.environment.location
os_type = "Windows"
sku_name = "Y1"
}
resource "azurerm_windows_function_app" "analytical-rules-back-function" {
name = "analytical-rules-backup-function"
resource_group_name = module.environment.resource_group_name
location = module.environment.location
storage_account_name = azurerm_storage_account.analytical-rules-backup-sa.name
storage_account_access_key = azurerm_storage_account.analytical-rules-backup-sa.primary_access_key
service_plan_id = azurerm_service_plan.analytical-rules-backup.id
site_config {}
}
Any ideas what to fix? Thank you
2
Answers
I fixed the problem.
When typing the repository name in the box the repository appears, I thought there would be a long list of repositories that I would scroll through.
I followed @pravallika KV's steps with creating deployment, in the deployment centre and used the github action yaml provided.
I created a directory with the relevant function code and provided the directory in the github action yaml.
Here, you have mentioned that trying to deploy function to Windows Application but in GitHub workflow I can see its
ubuntu-latest
Try Configuring deployment in Portal and it’ll generate the required workflow to deploy the function.
Go to
Function App=>Deployment Center=>Select GitHub as Source
and provide the repository of the function app, Save.Go to
Function App=>Advanced Tools=>Go, redirects to App's KUDU site=>Debug Console
(https://.scm.azurewebsites.net/DebugConsole), navigate tositewwwroot
and check if all the deployed Function files are available.I have created a PowerShell Azure Function and deployed to Azure using GitHub actions.
Project Structure:
Default generated GitHub workflow to deploy the Function to Azure Function app:
Deployed Successfully:
Portal: