Aditya Mishra
Aditya Mishra

Reputation: 1875

Combine multiple triggers with multiple branches

How can we run github workflows on multiple branches for multiple triggers? Example - How can I run a workflow on pull_request & push on say prod & dev? Refer the code snippet below

on: [push, pull_request]
  branches:    
    - 'dev'
    - 'prod'

The above isn't allowed. I get the following error -

Property branches is not allowed.yaml-schema: GitHub Workflow

How can I handle this?

Upvotes: 8

Views: 9918

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 22900

You can have multiple events triggering your workflow with subtypes.

Therefore, to achieve what you want (run a workflow on pull_request & push on prod & dev), you would need this implementation:

on:
  push:
    branches:    
      - 'dev'
      - 'prod'

  pull_request:
    branches:    
      - 'dev'
      - 'prod'

The problem in your implementation was that the branches isn't a on subtype in github actions, it's only a pull_request or push subtype.

Upvotes: 13

Related Questions