Environment Variable Repalce

I do not know of a CircleCI specific solution, but generally speaking, if you need to replace a term in a Git repo you can combine git grep and sed

- run:
    name: Replace build id
    command: |
      git grep -l '_buildNum' | xargs sed -i "s/_buildNum/${CIRCLE_BUILD_NUM}/g"

That would replace all occurrences of _buildNum in your repository.

You could potentially abstract that out into an Orb or even a command in your config.yml

This has not been tested for things like typos, but to get you started:

commands:
  replace:
    description: Replace a value in a git repository
    parameters:
      target:
        type: string
      replacement:
        type: string
    steps:
      - run: |
          git grep -l '<< parameters.target >>' | xargs sed -i 's/<< parameters.target >>/<< parameters.replacement >>/g'

  replace-environment-variable:
    description: Replace a value with an evironment variable in a git repository
    parameters:
      target:
        type: string
      replacement-env-var-name:
        type: string
    steps:
      - run: |
          git grep -l '<< parameters.target >>' | xargs sed -i "s/<< parameters.target >>/${<< parameters.replacement >>}/g"

Notice that we’ll need to do things a little bit differently for environment variables. This is because parameters are passed in a compile-time. Before the environment variables are available. So in this case, instead of passing in a value to replace, we’ll pass in the name of the environment variable (CIRCLE_BUILD_NUM) as opposed to the value 123.

Also, this is not fault-tolerant to special characters and other edge cases. For example if your replacement value contains a / or other characters that would cause issues with sed.