Pass initial CIRCLE_BUILD_NUM to all jobs of the workflow

envars
workflow
cci-20

#1

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?


#2

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: |
        CIRCLE_BUILD_NUM_DOCKER=${CIRCLE_BUILD_NUM}

        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
      paths:
        - 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)"

#3

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