Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 5

[GitHub Actions] branch conditional

Solved! Go to Solution.

I'd like to make a job or step (either would work for me) conditional in our workflow, and have it validate the current branch is "master". Is there something we can reference in the `if:` conditional to match only when the branch being pushed to is master?

4 Replies
Solution
Copilot Lvl 3
Message 2 of 5

Re: [GitHub Actions] branch conditional

You can do a conditional statement using this:

if: github.ref == 'refs/heads/master'

 

Geert van der Cruijsen (DevOps Consultant & Cloud Native Architect @ Xpirit Netherlands)
Copilot Lvl 2
Message 3 of 5

Re: [GitHub Actions] branch conditional

How did you know the value of `github.ref`? I can't find it.

Pilot Lvl 1
Message 4 of 5

Re: [GitHub Actions] branch conditional

Copilot Lvl 3
Message 5 of 5

Re: [GitHub Actions] branch conditional

You can print the value to verify:

 

steps:
    - run: echo ${{github.ref}}