DEV Community

0 seconds of 1 minute, 30 secondsVolume 90%
Press shift question mark to access a list of keyboard shortcuts
00:00
00:00
01:30
 
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.

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more