Warm tip: This article is reproduced from serverfault.com, please click

Pushing tags triggers CI/CD loop

发布于 2020-11-12 16:52:25

Im using CircleCI for CI/CD and recently wanted to start tagging my releases to main bransch. This is my config.yml

version: 2.1
orbs:
  node: circleci/node@1.1.6

jobs:
  build:
    executor:
      name: node/default
    steps:
      - checkout
      - node/with-cache:
          steps:
            - run: git pull
            - run: npm install standard-version
            - run: npm run release
            - run: git push --follow-tags origin master
      - node/with-cache:
         steps:
            - run: echo 'deploying master branch'

Ofcourse this triggers and endless loop since it creates a new push which triggers CircleCI... I've read that you can skip builds in commit messages by adding [ci skip] but pushing tags does not give that option.

How do I get around this? I want the semantic releases to be tagged automatically when a new version is released... Can I somehow get around this?

Im using standard-version for tagging and updating package.json.

Any help would be greatly appriciated

Questioner
Kmonassar
Viewed
0
Kmonassar 2020-11-30 20:58:46

The solution was the following changes to my config.yml:

version: 2.1
orbs:
  node: circleci/node@1.1.6

jobs:
  build:
    executor:
      name: node/default
    steps:
      - checkout
      - node/with-cache:
          steps:
            - checkout
            - run: npm install
            - run: npm run test
            - run: npx semantic-release
      - node/with-cache:
         steps:
            - run: echo 'deploying master branch'
            - run: ssh -v -o "StrictHostKeyChecking no" user@xxxx.xxx "cd ~/projects/xxx; git pull --rebase; ./publish.sh"

workflows:
  version: 2
  build_project:
    jobs: 
      - build:
          filters:
            branches:
              only: master 

When doing this with "- run: npx semantic-release", the version bumping step will be auto incremented and the commit tagged with [skip ci] so it doesnt loop.