DEV Community

0 seconds of 0 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
00:00
 
Brian Douglas for GitHub

Posted on • Edited on

17 3

Running GitHub Actions CI/CD triggers on specific branches

GitHub Actions allows you to automate, customize and execute your software development workflows inside your repository.

You can configure your workflows to run when specific activity on GitHub happens, at a scheduled time, or when an event outside of GitHub occurs.

The most common events are push and pull_request events to trigger workflow runs on any change to the main branch. The workflow will run for any pull request opened and show your workflows directly in the pull request.

on: [push, pull_request]
Enter fullscreen mode Exit fullscreen mode

You want certain events to run on specific branches. You adjust the YAML to include branch names to only run CI checks on branches you needed them. Below I have changed my events to run on the main branch, even though it is named the push. It will run when you run git push or merge a pull request into the main branch.

on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - main
Enter fullscreen mode Exit fullscreen mode

Finally, you can leverage YAML syntax to run an array of branches. You can also set up wildcards to run on similarly named branches as well. So now you can set up a workflow to run in multiple branches and maintain separate release tracks. For example:

on:
  push:
    branches:
    - master
    - 'releases/**'
  pull_request:
    branches:
    - master
    - 'releases/**'
Enter fullscreen mode Exit fullscreen mode

This is part of my 28 days of Actions series. To get notified of more GitHub Action tips, follow the GitHub organization right here on Dev.

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

Top comments (0)

Quickstart image

Django MongoDB Backend Quickstart! A Step-by-Step Tutorial

Get up and running with the new Django MongoDB Backend Python library! This tutorial covers creating a Django application, connecting it to MongoDB Atlas, performing CRUD operations, and configuring the Django admin for MongoDB.

Watch full video →

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay