BitBucket Pipeline - trigger on tag, steps based on branch

Viewed 769

Currently I have a project where the pipeline is branch controlled, different branches offering different places that it can deploy to (manual trigger steps once the branch commit started the pipeline).

We have recently added tagging with release version number, which means although the pipeline was kicked off by the commit to a branch, it doesn't have the tag, so I have had manually run what is essentially the same build again post tagging.

What I'm looking for is to change to automated tag build, which I know how to do, but offer manual steps after the trigger based upon the branch.

Any ideas?

1 Answers

One way to do it is to specify steps in the pipeline that runs when you push a tag. You can make the build automatic, but include a requirement to manually trigger the actual deployment. Your tag-based pipeline can simply duplicate the steps that you have for your branch deployment. The following will duplicate the deployment steps of a master branch, but based on tagging a commit as a release (e.g. 1.0.0) on any branch. The pipeline will automatically build when you tag, but requires a manual triggering of the deployment:

pipelines:
  branches:          
    master:
    - step: *Build
    - step: 
        <<: *Deploy
        name: Deploy to Prod
        deployment: prod
        trigger: manual

  tags:
    '*.*.*': # Tagged Release Version - automatically build, ready for manual deployment to Prod
      - step: *Build
      - step: 
          <<: *Deploy
          name: Deploy to Prod
          deployment: prod
          trigger: manual
Related