Trigger on master and tag

I want to trigger a workflow on master AND tag. So there must be a tag commited to master before this workflow triggers

on:
  push:
    branches:    
      - master
    tags:        
      - v*

Does the above fill the AND requirements or is this a master OR tag?

Hi @kaykhan,

Yes, confirmed on my side, it meets the AND requirements.

Happy coding!

It doesn’t ?, i tested using a different branch.

Taged pushed and the pipeline still ran even though it was not on master

Hi @kaykhan,

With your code, the workflow will be triggered when any commits to master branch, or any tag pushed to the repository.

I think there could be some misunderstanding of the ‘tag’, it’s not per-branch.
Could you please explain more about your requirements? an example would be much appreciated.

Thanks

its the and condition im looking for

The pipeline must run when its on master branch AND their is a tag.

So the pipeline shouldint run if the branch is test AND their is a tag

Hi @kaykhan,

Thanks for your quick reply!

It’s not supported to check 'commit AND tag' on event trigger since tag is not per-branch.

As an alternative, you can try to add push: branches: master as the trigger, check if the commit has a tag in the steps, skip the latter steps if there’s no tag.

Please refer the doc here for the tag check.

Thanks

Unfortunately this doesn’t work, as soon as you push the tag the push: branches: master condition is no longer met.

Hi @kaykhan,

Does your workflow file exist on master branch? If it is, when you use push: tags: -v* , the workflow will ONLY be triggered when you push a tag to master branch, not the other branches.

The push: branches: master and ‘push: tags: -v*’ are parall, any commit OR v* tag pushed to master branch will trigger the workflow. As I mentioned, it’s not supported to meet both conditions on event trigger at the same time.

In this case, your workflow file is not on master branch. If you don’t want to trigger the workflow by a tag, you can directly remove the tag trigger on the yaml file, or you can use below sample code to skip the job if it’s not master branch.

on: 
  push:
    tags: 
      - v*

jobs:
  job1:
    if: github.event.base_ref=='refs/heads/master'  # check the branch, if it's not master, skip the job.
    runs-on: [ubuntu-latest]
    steps:

Hope it’s clear and helpful!