Help with workflow

Hi Everyone, I have the below config.yml, and I can’t for the life of me work out why all the jobs continue to run despite me seemingly configuring it so that it needs me to tag a commit to run certain ones.

version: 2.1

jobs:
deploy_app1:
machine: true
steps:
- checkout
- run:
name: Deploy App1 Over SSH
command: |
ssh circleci@my_ip “~/deployApp1.sh”

deploy_app2:
machine: true
steps:
- checkout
- run:
name: Deploy App2 Over SSH
command: |
ssh circleci@my_ip “~/deployApp2.sh”

deploy_both:
machine: true
steps:
- checkout
- run:
name: Deploy Both App1 and App2 Over SSH
command: |
ssh circleci@my_ip “~/deployBoth.sh”

workflows:
version: 2
build-and-deploy:
jobs:
- deploy_app1:
filters:
branches:
only: main
tags:
only: /^deploy-app1./
- deploy_app2:
filters:
branches:
only: main
tags:
only: /^deploy-app2.
/
- deploy_both:
filters:
branches:
only: main
tags:
only: /^deploy-both.*/

Can someone please explain how I can configure my workflow so that I can tag a commit with “deploy-app1” to deploy just app1, “deploy-app2” to deploy app2, or “deploy-both” for it to run that job that deploys both? Could it be that the branch filter overrides the tags or something - which is why CircleCI is still running all jobs for any commit on main (I don’t have to tag anything)

thanks in advance.

I think I worked it out from another post (I’d link it but I’m not allowed apparently)

I need to ignore the branch and just work from tags.

1 Like

Technically, tags are not associated with a branch. So if the behavior is you want to trigger on a tag being cut and not on a push to, e.g., main, you will want to ignore branches * on the workflow.

Also watch out for one other quirk of Circle, which is that within workflows, if you have a filter on tags or branches in one job, you may need to explicitly ignore the opposite (I don’t remember the exact details, but, for example, if one job is filtering on branch foo, and another on a tag pattern like ^v\d+\.\d+\.d+, you may need to explicitly add an ignore: * for tags on the jobs with the branch filter, and likewise, ignore * for brnaches on the jobs with the tag filter. May want to search a little more and / or do some tests.

Sometimes it’s simpler to make a separate workflow for the items (let’s say a deploy) you want to happen when a tag is cut, or you can use YAML anchors to DRY up the config a little.

side note: In the future, if you wrap your config in a code block / triple backticks (with yaml next to the first line), it will be a lot easier to read your example.