python - Unable to deploy the Time Triggers in Azure Function with Github but works with VSCode - Stack Overflow

I am trying to deploy the 2 time trigger functions with github resulting the 0 function found in the Lo

I am trying to deploy the 2 time trigger functions with github resulting the 0 function found in the Log Stream

Github Directory

function_app.py


import logging
import azure.functions as func

app = func.FunctionApp()

@app.timer_trigger(schedule="0 0 * * * *", arg_name="myTimer", run_on_startup=False,
              use_monitor=False)

def timer_trigger_BOT1(myTimer: func.TimerRequest) -> None:
    
    if myTimer.past_due:
        logging.info('The timer is past due!')
    
    # MAIN FUNCTION TO EXECUTE

    logging.info('Python timer trigger function executed.')


@app.timer_trigger(schedule="0 0 23 * * *", arg_name="myTimer", run_on_startup=False,
              use_monitor=False)

def timer_trigger_BOT2(myTimer: func.TimerRequest) -> None:
    
    if myTimer.past_due:
        logging.info('The timer is past due!')
    
    # MAIN FUNCTION TO EXECUTE

    logging.info('Python timer trigger function executed.')

.yml file

# Docs for the Azure Web Apps Deploy action: 
# More GitHub Actions for Azure: 
# More info on Python, GitHub Actions, and Azure Functions: 

name: Build and deploy Python project to Azure Function App - INFO-at-flsmidthcom-Email-dispatch

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
  PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Python version
        uses: actions/setup-python@v5
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      - name: Install dependencies
        run: pip install -r requirements.txt

      # Optional: Add step to run tests here
      
      - name: Zip the deployment package
        run: zip -r release.zip . -x "*.git/*" -x "*.github/*"

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: python-app
          path: release.zip

  deploy:
    runs-on: ubuntu-latest
    needs: build
    
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip     
        
      - name: Login to Azure
        uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID}}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID}}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID}}

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: '<app_name>'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

I wanted to know if I am doing something wrong or if there is an error in the .yml file, or if the function is not being detected due to insufficient permissions in GitHub or Azure Function.

Additional Note: I am able to successfully deploy both triggers using VSCode, but the deployment with GitHub is not working.

What can be the possible reasons?

I am trying to deploy the 2 time trigger functions with github resulting the 0 function found in the Log Stream

Github Directory

function_app.py


import logging
import azure.functions as func

app = func.FunctionApp()

@app.timer_trigger(schedule="0 0 * * * *", arg_name="myTimer", run_on_startup=False,
              use_monitor=False)

def timer_trigger_BOT1(myTimer: func.TimerRequest) -> None:
    
    if myTimer.past_due:
        logging.info('The timer is past due!')
    
    # MAIN FUNCTION TO EXECUTE

    logging.info('Python timer trigger function executed.')


@app.timer_trigger(schedule="0 0 23 * * *", arg_name="myTimer", run_on_startup=False,
              use_monitor=False)

def timer_trigger_BOT2(myTimer: func.TimerRequest) -> None:
    
    if myTimer.past_due:
        logging.info('The timer is past due!')
    
    # MAIN FUNCTION TO EXECUTE

    logging.info('Python timer trigger function executed.')

.yml file

# Docs for the Azure Web Apps Deploy action: https://github/azure/functions-action
# More GitHub Actions for Azure: https://github/Azure/actions
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions

name: Build and deploy Python project to Azure Function App - INFO-at-flsmidthcom-Email-dispatch

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
  PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Python version
        uses: actions/setup-python@v5
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      - name: Install dependencies
        run: pip install -r requirements.txt

      # Optional: Add step to run tests here
      
      - name: Zip the deployment package
        run: zip -r release.zip . -x "*.git/*" -x "*.github/*"

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: python-app
          path: release.zip

  deploy:
    runs-on: ubuntu-latest
    needs: build
    
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip     
        
      - name: Login to Azure
        uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID}}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID}}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID}}

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: '<app_name>'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

I wanted to know if I am doing something wrong or if there is an error in the .yml file, or if the function is not being detected due to insufficient permissions in GitHub or Azure Function.

Additional Note: I am able to successfully deploy both triggers using VSCode, but the deployment with GitHub is not working.

What can be the possible reasons?

Share Improve this question asked Jan 29 at 8:01 krrishkrrish 11 bronze badge 1
  • Are you getting any error while deploying this using github actions? – Ikhtesam Afrin Commented Jan 29 at 8:12
Add a comment  | 

1 Answer 1

Reset to default 0

I have the same code in function_app.py file alike you.

I am trying to deploy the codes to function app using GitHub action with the help of below given script.

name: Build and deploy Python project to Azure Function App - afreeen-fa

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' 
  PYTHON_VERSION: '3.11' 

jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read 

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Python version
        uses: actions/setup-python@v5
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: python-app
          path: |
            release.zip
            !venv/
  deploy:
    runs-on: ubuntu-latest
    needs: build
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip     
        
      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: 'afreeen-fa'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_BEA2A185EB094***8218 }}

Post successful deployment, I can see the functions in function app's Overview blade as shown below.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745305661a4621693.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信