Pass initial CIRCLE_BUILD_NUM to all jobs of the workflow



I have a workflow with multiple steps.
I want to be able to pass the initial job’s CIRCLE_BUILD_NUM to all the downstream jobs.
Is that possible?


Looking at the environment variables in the “Spin up Environment” step, it seems there’s no initial build num saved for a workflow. You could either use the CIRCLE_WORKFLOW_ID which is consistent for all workflow jobs or use this workaround we use instead:

[first job]
  - deploy:
      name: Save build number (for deploy steps)
      command: |

        mkdir -p /tmp/workspace/docker-build
        cd /tmp/workspace/docker-build
        echo ${CIRCLE_BUILD_NUM_DOCKER} > docker-build_number.txt
  - persist_to_workspace:
      root: /tmp/workspace
        - docker-build

[consecutive job]
  - attach_workspace: &attach_workspace
      at: /tmp/workspace
  - run:
       name: Use the saved build number here
       command: |
             export CIRCLE_BUILD_NUM_DOCKER="$(cat /tmp/workspace/docker-build/docker-build_number.txt)"


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