Answers: <p>This is the approach I came up with.  It's kinda ugly, but it does work:</p>
  
  <pre><code>- run:
      name: Create unique build identifier
      command: |
          GIT_SHA=$( git rev-parse --short HEAD )
          echo "export GIT_SHA=${GIT_SHA}" &gt;&gt; "${BASH_ENV}"
  
          # the always-increasing counter, based on CIRCLE_BUILD_NUM
          BUILD_COUNTER="${CIRCLE_BUILD_NUM}"
          echo "export BUILD_COUNTER=${BUILD_COUNTER}" &gt;&gt; "${BASH_ENV}"
  
          # the build identifier, which includes the short git sha
          BUILD_NUMBER="CIRC${BUILD_COUNTER}-${GIT_SHA}"
          echo "export BUILD_NUMBER=${BUILD_NUMBER}" &gt;&gt; "${BASH_ENV}"
  
          # output build id and counter
          echo -e "\nbuild counter: ${BUILD_COUNTER}; build id: ${BUILD_NUMBER}\n"
  </code></pre>
  
  <p>Then <code>${BUILD_NUMBER}</code> is available as an environment variable in other steps.</p>
  
Answers: CC BY-SA 4.0
Answers: 2022-12-22T10:53:29.533Z
Answers: `${BUILD_NUMBER}` won't be available in other jobs and this is what the question was about
Answers: dgpro
Answers: CC BY-SA 4.0
Answers: 2019-10-25T14:18:09.557Z
Answers: 2019-10-25T14:18:09.557Z
Answers: blalor
Answers: <p>In v2.1 config you can use <a href="https://circleci.com/docs/pipeline-variables/#introduction" rel="nofollow noreferrer">pipeline values</a>, specifically <code>pipeline.number</code>. This number is the same across all jobs in a workflow. (Indeed, across all workflows in the pipeline.) You can use it like this:</p>
  <pre class="lang-yaml prettyprint-override"><code>    steps:
        - run: echo Hello from pipeline number &lt;&lt; pipeline.number &gt;&gt;
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-02-01T11:08:29.613Z
Answers: 2024-02-01T11:08:29.613Z
Answers: Stig Brautaset
Body: <p>I use <code>$CIRCLE_BUILD_NUM</code> in different jobs in a workflow (but it seems like that get incremented in between jobs of the same workflow)?</p>
  
  <p>I did some research and it looks like I can switch to <code>CIRCLE_WORKFLOW_ID</code> which is unique for the workflow but then the ID is some really long string, not like the build number which is a small integer, nice that I can use to append to build numbers and docker tags and such.</p>
  
  <p>Any ideas?</p>
  
Tags: <docker><build-pipeline><circleci-2.0>
Title: Anyone know how to use $CIRCLE_BUILD_NUM across different jobs in CircleCI?
UserDisplayName: erotsppa
ThreadText: # Anyone know how to use $CIRCLE_BUILD_NUM across different jobs in CircleCI?
  
  (Asked by: username_0 on 2019-10-11)
  
  I use `$CIRCLE_BUILD_NUM` in different jobs in a workflow (but it seems like that get incremented in between jobs of the same workflow)?
  
  I did some research and it looks like I can switch to `CIRCLE_WORKFLOW_ID` which is unique for the workflow but then the ID is some really long string, not like the build number which is a small integer, nice that I can use to append to build numbers and docker tags and such.
  
  Any ideas?
  
  **Tags:** docker, build-pipeline, circleci-2.0
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-10-25. Score: 2
  
  This is the approach I came up with. It's kinda ugly, but it does work:
  
  ```
  - run:
      name: Create unique build identifier
      command: |
          GIT_SHA=$( git rev-parse --short HEAD )
          echo "export GIT_SHA=${GIT_SHA}" >> "${BASH_ENV}"
  
          # the always-increasing counter, based on CIRCLE_BUILD_NUM
          BUILD_COUNTER="${CIRCLE_BUILD_NUM}"
          echo "export BUILD_COUNTER=${BUILD_COUNTER}" >> "${BASH_ENV}"
  
          # the build identifier, which includes the short git sha
          BUILD_NUMBER="CIRC${BUILD_COUNTER}-${GIT_SHA}"
          echo "export BUILD_NUMBER=${BUILD_NUMBER}" >> "${BASH_ENV}"
  
          # output build id and counter
          echo -e "\nbuild counter: ${BUILD_COUNTER}; build id: ${BUILD_NUMBER}\n"
  
  ```
  
  Then `${BUILD_NUMBER}` is available as an environment variable in other steps.
  
  > **Comments:**
  > **username_2**: `${BUILD_NUMBER}` won't be available in other jobs and this is what the question was about  
  
  ---
  
  ### Answer by username_3 on 2024-02-01. Score: 0
  
  In v2.1 config you can use [pipeline values](https://circleci.com/docs/pipeline-variables/#introduction), specifically `pipeline.number`. This number is the same across all jobs in a workflow. (Indeed, across all workflows in the pipeline.) You can use it like this:
  
  ```yaml
      steps:
        - run: echo Hello from pipeline number << pipeline.number >>
  
  ```
  
  
  ---
  
  