Answer
GitHub Actions Triggers (Events)
The on: key defines what event causes the workflow to run.
push — Trigger on Code Push
YAML
on:
push:
branches:
- main
- develop
- 'release/**' # wildcard: release/1.0, release/2.0
branches-ignore:
- 'dependabot/**'
paths:
- 'src/**' # only trigger if files in src/ changed
- 'pom.xml'
paths-ignore:
- '**.md' # ignore markdown file changes
- 'docs/**'
pull_request — Trigger on PR Events
YAML
on:
pull_request:
branches: [main, develop] # PRs targeting these branches
types:
- opened # new PR created
- synchronize # new commit pushed to PR
- reopened # PR reopened
- ready_for_review # draft → ready
schedule — Run on a Timer (Cron)
YAML
on:
schedule:
- cron: '0 2 * * *' # every day at 2:00 AM UTC
- cron: '0 22 * * 1-5' # weekdays at 10 PM UTC
- cron: '0 0 * * 0' # every Sunday at midnight
# Cron format: minute hour day-of-month month day-of-week
# H = hash in Jenkins, but GitHub Actions uses standard cron only
workflow_dispatch — Manual Trigger with Inputs
YAML
on:
workflow_dispatch:
inputs:
environment:
description: 'Target environment'
required: true
default: 'staging'
type: choice
options: [staging, qa, production]
browser:
description: 'Browser to test with'
required: true
default: 'chrome'
type: choice
options: [chrome, firefox, edge]
run_full_suite:
description: 'Run full regression?'
required: false
default: false
type: boolean
# Access inputs in steps:
# ${{ github.event.inputs.environment }}
# ${{ inputs.environment }} (newer syntax)
workflow_call — Trigger from Another Workflow
YAML
# Called by another workflow (reusable workflow)
on:
workflow_call:
inputs:
environment:
required: true
type: string
secrets:
deploy-key:
required: true
Multiple Triggers Together
YAML
on:
push:
branches: [main]
pull_request:
branches: [main, develop]
schedule:
- cron: '0 1 * * *' # nightly regression
workflow_dispatch: # manual trigger anytime
Trigger Context Variables
YAML
steps:
- name: Show trigger info
run: |
echo "Event: ${{ github.event_name }}" # push / pull_request / schedule
echo "Branch: ${{ github.ref_name }}" # main / develop
echo "Actor: ${{ github.actor }}" # who triggered it
echo "SHA: ${{ github.sha }}" # commit hash
echo "PR number: ${{ github.event.number }}" # only for pull_request
