'Dynamic jobs in within CircleCI workflow

Currently have a config.yml file with the following workflow jobs:

- build-test-staging:
          name: COM Staging Build
          filters:
            branches:
              only: /^release-.*/
          context: COM Deploy Settings
      - deploy-staging:
          name: COM Staging Deploy
          requires:
            - COM Staging Build
          filters:
            branches:
              only: /^release-.*/
          context: COM Deploy Settings
      - build-test-staging:
          name: UK Staging Build
          filters:
            branches:
              only: /^release-.*/
          context: UK Deploy Settings
      - deploy-staging:
          name: UK Staging Deploy
          requires:
            - UK Staging Build
          filters:
            branches:
              only: /^release-.*/
          context: UK Deploy Settings

There will be more of these, as well as a production version that has the same setup, but with different names.

As you can see, they all follow the same pattern: a name, a branch to run on (release for staging, master for production), and a context to bring in some env variables.

Without constant copy and pasting, is there a way to generate these jobs dynamically with something? I'm not too good at yml.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source