Add ability to persist an Environment Variable across workflows


There are cases when you need to persist an enviornment variable from one part of the workflow to be used by other parts of the workflow.

An example is the first build CIRCLE_BUILD_NUM, which may be used in later stages of the workflow (i.e. to identity an artifact, for example).


I’m also in need of such feature, so big +1

I’ve created a workflow which manages several jobs, few of them are build, upload deploy. The workflow is creating one bundle artifact which gets created in the “build” job, yet used in other “upload” and “deploy” jobs. Since CIRCLE_BUILD_NUM increments every job, it’s not a reliable method to index the bundle artifact. For example, if I use CIRCLE_BUILD_NUM to index two consecutive artifact bundles, one would be 10 and the next one would be 16. because a few jobs have run in between. It makes little sense, if I need to index the builds - for example, when building master branch.

I suggest adding a global environment variable per workflow such as CIRCLE_WORKFLOW_NUM which doesn’t change across the different build jobs of the workflow.

Without such a variable my bundle artifacts have no chance to be indexed consecutively. In order to access a specific artifact build number from other jobs in the workflow, I’ll need to hack around the missing environment variable. I’ll need to do something like:

echo $CIRCLE_BUILD_NUM > ~/some-cashed-stored-file
// now store file in cache ...
// create a bundle and name it ARTIFACT_TITLE

In a different, later job:
// restore cached store build number file, read build number 
RELEVANT_BUILD_NUM=$(cat ~/some-cashed-stored-file) 
aws s3 cp "$ARTIFACT_PATH" "s3://${S3_BUCKET}/${S3_BUNDLE_KEY}"
aws elasticbeanstalk create-application-version \
    --version-label "$ARTIFACT_TITLE" \
    --source-bundle "S3Bucket=${S3_BUCKET},S3Key=${S3_BUNDLE_KEY}" \
    --application-name "$APP_NAME"

I had CIRCLE_WORKFLOW_NUM, I wouldn’t need to do any of that messy build number storing and I’d have consecutively indexed builds

@CircleCI-Employees would it be possible to add CIRCLE_WORKFLOW_NUM?

Edit: allowing persistent storage which doesn’t get reset with “Build without cache” would also solve it. If that were the case, I’d be able to store the workflow number across workflows and increment it for each new workflow run


You can use “CIRCLE_WORKFLOW_ID”, but that is not in numeric format - it is more of a hex format.


There’s this:

but that is for custom set environment variables.