skip to Main Content

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:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#folder-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:
enter image description here

I’ve consulted the following documentation, but the issue persists:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-how-to-github-actions?tabs=windows%2Cpowershell&pivots=method-template

https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push

https://learn.microsoft.com/en-us/azure/azure-functions/functions-infrastructure-as-code?tabs=json%2Cwindows%2Cdevops&pivots=consumption-plan

https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-powershell?tabs=portal#folder-structure

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:
enter image description here

This leads me to believe the configuration of my azure function is incorrect:

enter image description here

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


  1. Chosen as BEST ANSWER

    I fixed the problem.

    1. 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.

    2. I followed @pravallika KV's steps with creating deployment, in the deployment centre and used the github action yaml provided.

    3. I created a directory with the relevant function code and provided the directory in the github action yaml.

    enter image description here


  2. I’ve encountered challenges deploying my PowerShell code from GitHub to an Azure Function (consumption plan windows).

    Here, you have mentioned that trying to deploy function to Windows Application but in GitHub workflow I can see its ubuntu-latest

    enter image description here

    • 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 to sitewwwroot 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:

    C:.
    |   .gitignore
    |   host.json
    |   local.settings.json
    |   profile.ps1
    |   requirements.psd1
    +---.vscode
    |       extensions.json
    |
    ---HttpTrigger
            function.json
            run.ps1
    
    • Deploying the application to Function App (Windows) with Consumption Plan.
    • Application Settings of the function app:

    enter image description here

    Default generated GitHub workflow to deploy the Function to Azure Function app:

    name: Build and deploy Powershell project to Azure Function App - <App_Name>
    
    on:
      push:
        branches:
          - main
      workflow_dispatch:
    
    env:
      AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
    
    jobs:
      build-and-deploy:
        runs-on: windows-latest
        steps:
          - name: 'Checkout GitHub Action'
            uses: actions/checkout@v4
    
          - name: 'Run Azure Functions Action'
            uses: Azure/functions-action@v1
            id: fa
            with:
              app-name: '<App_Name>'
              slot-name: 'Production'
              package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
              publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_F184054XXXXXXXX12620 }}
    

    Deployed Successfully:

    enter image description here

    Portal:

    • Could see the deployed function in Portal.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search