Trigger Job on branch created #26286
-
Hello, community. I didn’t find documentation on how to trigger an action when I’m creating a branch. What I want, on creating branch releases/** to trigger publish. Is it possible right now? |
Beta Was this translation helpful? Give feedback.
Replies: 16 comments 4 replies
-
When you push newly created branches to Github. You can watch on push events on the branch. https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#onpushpull_requestbranchestags |
Beta Was this translation helpful? Give feedback.
-
Hi @dmfilipenko , You can use the Create event to do this, mode details please reference here: |
Beta Was this translation helpful? Give feedback.
-
I tried
and
But I am still seeing jobs getting triggered by non-release branches. |
Beta Was this translation helpful? Give feedback.
-
The create event does not support branch filter and tag filter. Anytime you create a new branch or tag, the workflow will be triggered as long as the workflow runs on create event has been existing on the base ref of the new branch or tag. The push event does not have any Activity types. The activity type “created” you set on the push event does not exist. If your projects really need the feature that the create event supports branch filter and tag filter, I recommend that you can directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions. In addition, as the workaround, you can use the expression github.ref to get the name of the created branch from the github context, then add an if conditional on each job to skip all the jobs in the workflow according to the branch name.
|
Beta Was this translation helpful? Give feedback.
-
Thanks for this @brightran this is a really helpful workaround. I’ve submitted feedback from your link as there are still a few issues with this method, which I’ll just call out for anyone else who uses this method instead:
It would be great for GitHub to add first-party support for this functionality as it would improve UX and help GitHub actions be a lot more flexible for power users, which would help to achieve feature parity with other build agent competitors and make it more attractive to enterprise users with very complex requirements. |
Beta Was this translation helpful? Give feedback.
-
We have also sent a feature request for branch filter suport on the create event at Share feedback - GitHub Support. Hopefully it will arrive soon, so that way the action will not be triggered every time any branch is created. |
Beta Was this translation helpful? Give feedback.
-
Is there any news regarding built-in support of branches filter by the create event? |
Beta Was this translation helpful? Give feedback.
-
no filter for branch yet? 😦 |
Beta Was this translation helpful? Give feedback.
-
It would tremendously help us achieve our use-cases. I am voicing my concern for the delete event as well. @dannevesdantas Where is the request you created ? |
Beta Was this translation helpful? Give feedback.
-
@staticnotdynamic we have sent it through the old customer feedback form page last year. Looks like the old customer feedback form doesn’t exists anymore and now feature requests should be send via the Discussions · github-community/community · GitHub repo, by opening a discussion. I believe my feature request was lost when the old customer feedback form was discontinued. |
Beta Was this translation helpful? Give feedback.
-
I have searched for past issues (now discussions) in the new tracker but I couldn’t find something similar to our case. Would you please paste your original proposal there as a discussion ? If you did, please post back the discussion link so that we can all upvote it. |
Beta Was this translation helpful? Give feedback.
-
Do we have filter enabled on branch creation ? |
Beta Was this translation helpful? Give feedback.
-
Still hoping for filters on branch creation, like this :
|
Beta Was this translation helpful? Give feedback.
-
You can use on:
push:
branches:
- 'releases/**'
jobs:
Something:
if: github.event.created (thanks to @wizlif for taking the draft and getting it working in https://github.com/orgs/community/discussions/26286#discussioncomment-5826578) |
Beta Was this translation helpful? Give feedback.
-
Created a new discussion since this one is marked as answered but still no branch filter on the create event. |
Beta Was this translation helpful? Give feedback.
-
funny, why not support branch and tag filter. not support yet!!!!! |
Beta Was this translation helpful? Give feedback.
Hi @dmfilipenko ,
You can use the Create event to do this, mode details please reference here:
https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#create-event-create
Note: When you create a new branch, in the branch which the new branch is based on, the YAML file for the Create event workflow must have been existing, otherwise the new branch will not trigger the workflow run.