Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

trigger pipeline based on tag on branch

dschneider March 16, 2023

Is there any way to trigger a pipeline based on a tag on a branch?

currently I'm using :

 

pipelines:
default:
- step: *build-package
- step: *generate-docs

tags
:
v*.*.*:
- step: *build-package
- step: *generate-docs
- step: *publish-docs
but I would like the default to only apply to dev branches (exclude master) and then master branch to only build when a tag is applied. 

3 answers

1 accepted

0 votes
Answer accepted
dschneider March 17, 2023

To answer my own question, a couple links online suggest that bitbucket does not let you exclude branches so I need to create a dummy branch trigger for master. I haven't had a chance to push anything to master so this is untested but I think it should only trigger a build on master when a tag is pushed. :fingers-crossed:

 

pipelines:
branches:
'**':
- step: *build-package
- step: *generate-docs
'master':
- step:
script:
- echo "nothing to do for master branch"
tags:
v*.*.*:
- step: *build-package
- step: *generate-docs
- step: *publish-docs
1 vote
MiguelQueiroz July 17, 2023

I need this too, because when pushing tags for the staging branch, it does into the pipeline as "production too".

 

I used Bitrise before, and pipeline on a tag on a specific branch was totally possible. And I need commits to master with tags to trigger the pipeline. But only for master. To staging branch the steps are different.

0 votes
Riley Venable
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 16, 2023

Yes, you can trigger a pipeline based on a tag on a branch using the "Tags start condition" option in the bitbucket-pipelines.yml file.

dschneider March 16, 2023

can you provide anexample?

pipelines:
branches:
'**':
- step: *build-package
- step: *generate-docs
'master':
tags:
v*.*.*:
- step: *build-package
- step: *generate-docs
- step: *publish-docs

i tried something like this but I don't think you can nest tags under a branch. I really need to specify all branches except master for the first part and then have a separate tags section that applies to any branch 

Like # people like this
dschneider March 16, 2023

Would this make sense to exclude master except when tags are pushed to master?

pipelines:
branches:
'[!master]**':
- step: *build-package
- step: *generate-docs

tags:
v*.*.*:
- step: *build-package
- step: *generate-docs
- step: *publish-docs

 

Like Tommo likes this
MiguelQueiroz July 17, 2023

An example would be nice, because I need to only trigger the pipeline when on master branch and with tags "*.*.*"

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events