How to ignore branch names on pull requests ?

I am trying to ignore specific branches starting with a certain name pattern if a pull request event happens.

This is not working:

name: My action name for pull requests
on:
  pull_request:
    types: [edited]
    branches-ignore:
      - 'myPattern-**'

I think it is because ignore_branches in the context of pull request events is checking the target branch names and not the actual pull request names?

How can I exclude a pull request branch name instead?
Thanks.

1 Like

UPDATE:

I am able to exclude the job steps for specific branches with adding this condition on every step:

steps:
      - name: Checkout code
        uses: actions/checkout@master
        if: startsWith(github.head_ref, 'myPattern-') == false
        ....

Still this triggers the job in the beginning which I want to prevent in the first place.

I am happy if someone can help me out with excluding the branch at the top level when defining which event should trigger this action.

Thanks.

1 Like

branches-ignore hasn’t been working for me, and the github editor doens’t seem to recongize it as a filter, suggesting I use “branches” instead. Seems like a few bugs wrapped up in this?

I was trying branches instead of branches-ignore as well.

But still in the context of a pull request this is not working as appearently in this case not the actual branch name but the target name is taking into account - I guess:

name: My action for pull requests
on:
  pull_request:
    types: [edited]
    branches:
     - !develop # if target branch of the PR is develop this job will not run
     - '!myPattern-**' # no target branch with this name exists ... job will run
1 Like

@lisabaut wrote:

I think it is because ignore_branches in the context of pull request events is checking the target branch names and not the actual pull request names?

This is correct, the branches and ignore_branches relate to the TARGET branch of a PR. Not your head branch. But you can check the head branch in your workflow and don’t run the jobs if they match any given pattern, like the example you already posted earlier. At this point, that’s the only way to achieve what you want.

3 Likes

the branches and ignore_branches relate to the TARGET branch of a PR.

This solves my issue.

Example:

on:
  pull_request:
    branches-ignore:
      - 'master'

This ignores PR from any branches to master branch.