Skip to main content

Trigger

A CI/CD trigger is the event that starts a pipeline run, such as a push, pull request, tag, schedule, manual dispatch, or webhook.

Understanding CI/CD Triggers

What Is a Trigger and Which Types Matter

A trigger tells a pipeline when to run and with what context. Different events should start different pipelines: a feature branch push runs tests, a merge to main deploys to staging, and a version tag deploys to production. Getting this right avoids wasted minutes and accidental deploys.

Trigger Typical use
push Run CI on new commits
pull_request Validate before merge, no deploy
tag Release to production
schedule Nightly scans, drift checks
workflow_dispatch Manual run with inputs
webhook External systems such as alerts
flowchart LR A[Push to feature branch] --> D[Run tests] B[Merge to main] --> E[Deploy staging] C[Tag v1.2.3] --> F[Deploy production] classDef ev fill:#F97316,color:#FFFFFF classDef act fill:#326CE5,color:#FFFFFF class A,B,C ev class D,E,F act

Complete Trigger Configuration

Each event key may appear only once in a workflow, so branches and tags for push go under the same key.

YAML
on:
push:
branches:
- main
- 'release/**'
tags:
- 'v*.*.*'
paths:
- 'src/**'
- 'Dockerfile'
- '.github/workflows/**'
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
schedule:
- cron: '30 20 * * *' # 20:30 UTC is 02:00 IST the next day
workflow_dispatch:
inputs:
environment:
description: Target environment
required: true
default: staging
type: choice
options: [staging, production]

When both branches and tags are listed under push, the workflow runs for pushes that match either filter. Path filters apply to branch pushes and do not apply to tag pushes.

GitLab CI Trigger Rules

YAML
deploy-production:
stage: deploy
script:
- ./deploy.sh production
rules:
- if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/
when: manual
- when: never

Practical Commands

Bash
# Manual run with inputs
gh workflow run deploy.yaml --field environment=staging
# Trigger through the API
curl -X POST \
-H "Authorization: Bearer $GITHUB_TOKEN" \
https://api.github.com/repos/zerodha/kite-api/actions/workflows/deploy.yaml/dispatches \
-d '{"ref":"main","inputs":{"environment":"staging"}}'
# Create a tag to start a release pipeline
git tag -a v1.2.3 -m "Release v1.2.3"
git push origin v1.2.3

Troubleshooting

Symptom Check What to look for
Not triggering on push Branch and path filters Exact name or path match
Trigger loop Who creates commits Pipeline commits retriggering itself
Schedule not running Cron syntax and repo activity Invalid cron or disabled schedule
Tip

Use path filters so documentation-only changes skip the full pipeline, saving runner minutes and attention.

Remember

On GitHub, scheduled workflows in public repositories are disabled after 60 days without repository activity. Re-enable them if a nightly job silently stops.

Security

Be careful with pull_request_target. It runs with access to secrets even for fork pull requests. Use pull_request for untrusted code.

Common Mistake

Running the full deploy pipeline on every push to every branch. Scope deploy jobs to main or tags and protect main so deploys follow deliberate merges.

Frequently Asked Questions

Besides a push, which triggers matter most in production pipelines?

Pull request triggers validate changes before merge, schedules run nightly scans or drift checks, manual dispatch gates sensitive deploys behind a human, and webhooks let external systems start pipelines.

Why did my pipeline trigger itself in a loop?

A job probably commits or tags something that matches its own trigger. Skip runs for bot commits, use a skip marker in the commit message, or filter by branch or path.

How do I run a pipeline only for releases?

Trigger on version tags such as v1.2.3 and gate the deploy job on that tag pattern, optionally behind a manual approval. ===

Found a mistake, an outdated step or a broken link?