Deploy on Tag / Branch combination

circle.yml

#1

Hi,

basically I have 3 git branches (dev, test, master) that I’m using.
What I want to achieve is to trigger the deployment process depending on tags that are being pushed to specific branches.

Example:

When somebody pushes the tag “bla_1.0-deploy-to-dev” to the dev branch, then this branch will get checked out / built / deployed to my dev system.

When somebody pushes the tag “bla_1.0-deploy-to-test” to the test branch, then this branch will get checked out / built / deployed to my test system.

When somebody pushes the tag “bla_1.0-deploy-to-prod” to the master branch, then this branch will get checked out / built / deployed to my prod system.

It is important to prevent a deployment triggered by committing the “bla_1.0-deploy-to-prod” tag to the dev or test branch for example.
So my question is: Is it possible to define that only tag / branch combinations trigger specified deployment jobs.

For now I have this config:

version: 2

jobs:
  "deploy":
    machine: true
    working_directory: ~/repo    
    steps:
      - checkout
      - run:
          name: Deploy Git training project
          command: |
            echo "Deploying..."
workflows:
  version: 2
  build-and-deploy:
    jobs:
      - deploy:
          filters:
            tags:
              only: /.*deploy-to-development$/
            branches:
              ignore: /.*/

Like this I was able to trigger the job on committing a specific tag only (and not by committing to a branch only).
Any ideas?

Thanks a lot


#2

I also want to achieve workflow with Tag/Branch combo but couldn’t find the way


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.


#4

Reopening this, I’m curious—

Has anyone achieved this functionality via something like this (semi-pseudocoded)?

jobs:
  branch_tag_check:
    steps:

- run:
    name: check if branch AND tag conditions are met
    command: |
      if [[ ! ($CIRCLE_BRANCH == "only-this-branch" && \
        $CIRCLE_TAG == "only-this-tag") ]]
      then
        exit 1
      else
        echo "rest of jobs can proceed"
      fi

And then—

workflows:
  version: 2
  branch&&tag_filter:
    jobs:
      - branch_tag_check
      - rest_of_jobs:
          requires:
            - branch_tag_check

Would result in a “failed” job in the UI when actually your control flow is just working as-expected, but functionally I think this would work, no?

EDIT: actually, I think there may be a misunderstanding about how exactly git tags work. Which was just cleared up for me, as well! E.g.—

There’s no such thing as a tagged commit to master. Tags don’t have a branch.

@FelicianoTech’s comments here seem like a better approach: