How can I overwrite the BITRISE_BUILD_NUMBER env var for a single build?

How can I overwrite the BITRISE_BUILD_NUMBER env var for a single build?

E.g. if I re-run a specific commit, it’ll run with a new build number, which might be invalid since it won’t line up directly in chronological order. Is it possible to specify a previous build number for the build?

That’s a good question! Indeed the build number is a constantly increasing number and not designed to be reused in another build.

Fortunately there’s a fairly simple option to overwrite the build number or any default env var exposed by bitrise.io for a single build:

  1. Trigger the build manually, using the “Start/Schedule a build” button
  2. Switch to Advanced mode in the popup
  3. Specify the env var you want to overwrite in “Custom Environment Variables

You can of course do this via the API as well, more info & the related docs: http://devcenter.bitrise.io/api/build-trigger/#specify-environment-variables

This way, for this single build the BITRISE_BUILD_NUMBER env var will be overwritten with the value you provide.

Of course the build number on the web UI won’t reflect this, as that’s not read from this variable, but any script in the build will get the value you specify.

2 Likes