Passing variables from workflows to jobs (AKA parameterising jobs)


#1

I’d like to make my jobs to accept parameters. Ideally, I should be able to pass the parameters to the jobs in the workflows. Here is an example:

version: 2
jobs:
  deploy:
    docker:
      - image: circleci/python:3.6.5
    steps:
      - run:
          name: checkout deployment repo
          command: |
            mkdir -p ~/.ssh/
            touch ~/.ssh/known_hosts
            ssh-keyscan -H github.com >> ~/.ssh/known_hosts
            git clone git@REDACTED/deployment.git
            cd deployment/
            pipenv run fab deploy:presentation,<ENV_TO_DEPLOY>,$CIRCLE_BRANCH

workflows:
  version: 2

  build_and_deploy_staging:
    jobs:
      - build:
          filters:
            branches:
              only: develop
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: develop

  build_and_deploy_production:
    jobs:
      - build:
          filters:
            branches:
              only: master
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

I want to be able to pass ENV_TO_DEPLOY from workflows to the job. Otherwise, I have to duplicate deploy job. Does not seems DRY!


#2

Maybe contexts would help to accomplish this:

https://circleci.com/docs/2.0/contexts/


#3