Override top parameters

Hello, I have in my configuration top parameters:

version: 2.1
parameters:
  active_cluster:
    type: string
    default: aaaa
  standby_cluster:
    type: string
    default: bbbb
  destroy_standby_cluster:
    type: boolean
    default: false

I can get this parameters with using pipeline.parameters.active_cluster . Is it possible to change this value later in flow? I want to have this value different on each environment. For example on develop I want to have it set to XXX but on test I want to have default value of active_cluster. Is it possible to do? Or maybe I can do it in different way? I want to avoid a lot of changes while changing active cluster.

Pipeline parameters are by their nature static across the whole workflow that they are passed into.

If you need the parameters passed to jobs to change based on runtime values, such as a tag one solution is to basically build a switch statement within your config.yml that sets parameters passed jobs based on whatever is ‘switched’.

Below is a code snippet showing such a switch statement, things to note are

  • it uses yaml’s ‘&’ and ‘<<: *’, which are yaml’s anchor and reference elements that remove duplication of common text.
  • Based on the value of pipline.git.tag the job build-runner-latest-from-branch is called with a different value by defining workflows with conditions.
  • The value received by build-runner-latest-from-branch is then passed onto different commands.

This code also hints at a more complex part of my configuration - I used a third-party service called Doppler which is a secret store. So the value I am passing around allows access to a config held at Doppler that contains all the parameter values I need to access for the selected workflow.

version: 2.1

executors:
  exec_node:
    machine:
      image: ubuntu-2004:current
    resource_class: medium

orbs:
  jq: circleci/jq@2.2.0
  jira: circleci/jira@1.3.1
  slack: circleci/slack@4.8.3

  ##common values (think variables, structs and the like)

  tag_filters: &tag_filters
    filters:
      tags:
        only:
          - /^[vV].[0-9]+.*/
          - /^[0-9a-zA-Z]+.*/
      branches:
        ignore: /.*/


commands:

  ........

jobs:
  build-runner-latest-from-branch:
    executor: exec_node
    parameters:
      doppler_token:
        type: string
    steps:
      - clean_up_workspace
      - clean_up_docker_cache
      - show_system_details
      - docker_show_version
      - checkout
      - generate_info_file
      - build_application_and_container:
          doppler_token: "<<parameters.doppler_token>>"
      - docker_login:
          doppler_token: "<<parameters.doppler_token>>"
      - docker_tag_image:
          doppler_token: "<<parameters.doppler_token>>"
      - docker_push_image:
          doppler_token: "<<parameters.doppler_token>>"
      - deploy_to_target:
          doppler_token: "<<parameters.doppler_token>>"
      - slack_general_status_report
      - clean_up_docker_cache
      - clean_up_workspace

workflows:

  Backend-dev2:
    when:
      or:
        - matches: { pattern: "^[0-9a-zA-Z]+.ci-dev2" , value:  << pipeline.git.tag >> }
    jobs:
      - build-runner-latest-from-branch:
          doppler_token: "dp.st.base_dev2.arhORH"
          <<: *tag_filters

  Backend-production:
    when:
      or:
        - matches: { pattern: "^[0-9a-zA-Z]+.ci-prod" , value:  << pipeline.git.tag >> }
    jobs:
      - build-runner-latest-from-branch:
          doppler_token: "dp.st.base_production.StAGEcLN"
          <<: *tag_filters