You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GitHub Actions将Flask API部署至Google Cloud Functions

解决GitHub Actions部署Cloud Functions时的"No event triggers defined in on"错误

你在通过GitHub Actions将Flask API部署到Google Cloud Functions的过程中,已完成GCP侧工作负载身份池、身份提供者配置及服务账号IAM权限设置,但Workflow配置文件触发如下错误:

Error: .github#L1
No event triggers defined in on

问题原因

GitHub Actions工作流配置文件必须通过on字段明确定义触发事件,否则系统无法判断何时执行部署任务。你的现有配置仅包含jobs部分,缺少触发规则定义。

修复方案

在jobs字段上方添加on配置,指定工作流触发条件。以下是补充触发规则后的完整配置示例:

on:
  # 代码推送到main分支时自动触发部署
  push:
    branches: [ "main" ]
  # 允许在GitHub页面手动触发工作流(用于测试)
  workflow_dispatch:

jobs:
  job_id:
    runs-on: ubuntu-latest
    permissions:
      contents: 'read'
      id-token: 'write'

    steps:
    - uses: actions/checkout@v3

    - id: auth
      uses: google-github-actions/auth@v0
      with:
        workload_identity_provider: 'projects/XXX/locations/global/workloadIdentityPools/engineering-pool/providers/my-provider'
        service_account: 'engineering-infra@appspot.gserviceaccount.com'

    - id: 'deploy'
      uses: 'google-github-actions/deploy-cloud-functions@v0'
      with:
        name: 'my-flask-api'
        runtime: 'python3.10'

    # 测试部署后的API
    - id: 'test'
      run: 'curl "${{ steps.deploy.outputs.url }}"'

可选触发规则说明

你可根据需求调整on字段配置:

  • 仅在PR合并到main分支时触发:
on:
  pull_request:
    types: [ closed ]
    branches: [ "main" ]
  • 定时触发(每天凌晨2点执行):
on:
  schedule:
    - cron: '0 2 * * *'

内容的提问来源于stack exchange,提问作者Europa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 07:45:53