Conditional tunneling in .circleci/config.yml

circle.yml

#1

I am currently working on a project that requires me to version my releases following semantic versioning scheme.
I want to be able to approve a given job(one out of three jobs) and then that job versions my current release and then proceeds to the next job.
currently I made all three jobs wait for approval, and when I approve one, the remaining two still wait for approval hence the workflow remains on hold.
any ideas on how to achieve my end goal?


#2

@davidmukiibi not quite sure I understand here, but you can make the other two jobs dependent on your ‘approval’ job so they will flow on once you have approved it.
Can you share your config.yml (or the appropriate workflow section of it) to help explain further?


#3

hullo @edkellena, here is the .circleci/config.yml

defaults: &defaults
docker:
- image: circleci/python:2.7.13
environment:
PGUSER: circleci
TODO_ENV: testing
DATABASE_URL: postgresql://circleci@localhost/todo_test

- image: circleci/postgres:9.6
  environment:
    POSTGRES_USER: circleci
    POSTGRES_DB: todo_test
    POSTGRES_PASSWORD: ""

working_directory: ~/app

version: 2
jobs:
build:
docker:
- image: circleci/python:2.7.13

working_directory: ~/app

steps:
  - checkout
  - restore_cache:
      keys:
      - v1-dependencies-{{ checksum "requirements.txt" }}
      - v1-dependencies-

  - run:
      name: install dependencies
      command: |
        virtualenv venv
        source venv/bin/activate
        pip install -r requirements.txt
  - save_cache:
      paths:
        - ./venv
      key: v1-dependencies-{{ checksum "requirements.txt" }}

test:
<<: *defaults
steps:
- checkout
- run:
name: Waiting for Postgres to be ready
command: |
for i in seq 1 10;
do
nc -z localhost 5432 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Postgres && exit 1
- restore_cache:
keys:
- v1-dependencies-{{ checksum “requirements.txt” }}
- v1-dependencies-

  - run:
      name: run tests
      command: |
        source venv/bin/activate
        nosetests --rednose

coverage:
<<: *defaults
steps:
- checkout
- run:
name: Waiting for Postgres to be ready
command: |
for i in seq 1 10;
do
nc -z localhost 5432 && echo Success && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Postgres && exit 1
- run: mkdir test_reports
- restore_cache:
keys:
- v1-dependencies-{{ checksum “requirements.txt” }}
- v1-dependencies-

  - run:
      name: run tests
      command: |
        source venv/bin/activate
        nosetests --rednose --with-coverage --cover-inclusive --cover-package=todo --cover-erase --cover-html
        COVERALLS_REPO_TOKEN=NbqVl5cJLcD5rtNVQCd4N4kRORntFwykB coveralls
  - store_artifacts:
      path: test-reports
      destination: test-reports

no-bump:
docker:
- image: circleci/python:2.7.13

working_directory: ~/app
steps:
  - run: exit 0

bump-patch:
docker:
- image: circleci/python:2.7.13
environment:
BUMP_LEVEL: patch

working_directory: ~/app

steps:
  - checkout
  - run: bash bump-version.sh

bump-minor:
docker:
- image: circleci/python:2.7.13
environment:
BUMP_LEVEL: minor

working_directory: ~/app

steps:
  - checkout
  - run: bash bump-version.sh

bump-major:
docker:
- image: circleci/python:2.7.13
environment:
BUMP_LEVEL: major

working_directory: ~/app

steps:
  - checkout
  - run: bash ./bump-version.sh

deployment:
docker:
- image: circleci/python:2.7.13

working_directory: ~/app

steps:
  - checkout
  - run: bash .circleci/setup-heroku.sh
  - add_ssh_keys:
      fingerprints:
        - "39:79:40:24:11:64:bc:6f:e8:b4:be:7a:18:c5:b6:84"
  - deploy:
      name: Deploy Master to Heroku
      command: |
        if [ "${CIRCLE_BRANCH}" == "master" ]; then
          git push heroku master
          heroku run python manage.py db upgrade
          heroku restart
        fi

workflows:
version: 2
build_test_coverage_and_deployment:
jobs:
- build
- test:
requires:
- build
- coverage:
requires:
- test
- no-bump:
type: approval
requires:
- coverage
- bump-patch:
type: approval
requires:
- coverage
- bump-minor:
type: approval
requires:
- coverage
- bump-major:
type: approval
requires:
- coverage
- deployment:
requires:
- no-bump
- bump-patch
- bump-minor
- bump-major


#4

pardon the poor editing of the file… still new to this site and its editor


#5

Ok, I think I understand. Currently workflows does not support the logic that you want to do here, where it will proceed if one of those 3 jobs is approved. There would be alternative approaches available to you for the versioning however…

  • You could commit the version number into a file alongside your code changes that would then get read in a ‘bump’ type job on CircleCI.
  • You could use git tags to identify the version, and CircleCI could read the value of the tag to grab the version number.
  • You could set up separate workflows for each of the patch, minor and major paths you would want to follow, but probably have the approval step at the start of each, so that you can kick only one off, rather than wasting build time on all three.

If it were me, I’d go with git tagging, but it’s up to you!

Hope that helps.


#6

thanks a lot for your insight… very much needed help…


#7

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