如何通过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 inon
问题原因
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
相关产品推荐
相关产品推荐

