[Dynamic config] Get matching values in the mapping section

Hi there,

Can I get matching values in the mapping section for providing it to workflow?

For example:

  default:
    jobs:
      - path-filtering/filter:
          name: "Generating dynamic workflow based on changed files"
          mapping: |
            workspaces/.*/config.json workspace-updated true

I want instead of workspace-updated true provide workspace-updated $1. $1 will be a folder name of config.json.

Path filtering does not offer that functionality, but we had the same need on our team. You could implement it something like this with a custom job:

version: 2.1

setup: true

orbs:
  continuation: circleci/continuation@0.3.1
  vfcommon: voiceflow/common@0.32.0

workflows:
  generate-config:
    jobs:
      - generate-config

jobs:
  generate-config:
    docker:
      - image: cimg/base:stable
    steps:
      - checkout
      - vfcommon/get_changed_files # Use this command to put the list of changed files in `CHANGED_FILES`
          target_env_var: CHANGED_FILES
      - run:
          name: Set parameters # Set the workspace-updated parameter
          command: |
            WORKSPACE_UPDATED="$(echo "${CHANGED_FILES}" | grep 'workspaces/.*/config.json')"
            echo "{ \"workspace-updated\": \"${WORKSPACE_UPDATED}\" }" > "/tmp/pipeline-parameters.json"

      - continuation/continue:
          configuration_path: ".circleci/continue-config.yml"
          parameters: "/tmp/pipeline-parameters.json" # Pass along the parameters file you set in the previous step

We implemented vfcommon/get_changed_files to somewhat match the behaviour of path-filtering. It is implemented as follows, if you’re curious:

parameters:
  base_revision:
    description: Git revision to compare against
    type: string
    default: master
  target_env_var:
    description: Environment variable to set with the list of changed files
    type: env_var_name
    default: CHANGED_FILES
steps:
  - run:
      name: Put list of changed files in << parameters.target_env_var >> environment variable
      environment:
        BASE_REVISION: '<< parameters.base_revision >>'
        BASE="$(git merge-base $CIRCLE_SHA1 $BASE_REVISION)"
        # If we are on master, use the previous commit as the base
        if [[ $BASE == $CIRCLE_SHA1 ]]; then
          BASE="$(git rev-parse HEAD~1)"
        fi
        FILE_CHANGES="$(git diff --name-status --no-commit-id -r $BASE...$CIRCLE_SHA1)"
        echo "export << parameters.target_env_var >>=\"$FILE_CHANGES\"" >> "$BASH_ENV"

Hope this helps!

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