$BITRISE_BUILD_NUMBER_PIPELINENAME separated counters per workflows\pipelines

Hi, and thanks in advance!

What the feature?

We would appreciate if we have an opportunity (Bitrise feature, toggle) to separate build-counters depending on workflows/pipelines inside of the same Bitrise project.

The goal is: to get a sequential counter ($BITRISE_BUILD_NUMBER or another Bitrise variable like $BITRISE_BUILD_NUMBER_PIPELINENAME) with a step +1 in-a-row per every workflow/pipeline.

Why?

Our current flow: feature-branch → main → release, no tags.
We have 2 workflows: “PR validation/Review” and “App bundle creation/Build”.
We use $BITRISE_BUILD_NUMBER variable as versionCode(Android) value for building app bundles.

Bitrise runs “PR validation” builds for created and updated PR and increases $BITRISE_BUILD_NUMBER.
After completing PR, Bitrise runs “App bundle creation” build, and versionCode gets value from $BITRISE_BUILD_NUMBER.
Having versionCode = $BITRISE_BUILD_NUMBER is useful for further troubleshooting, for example.

It would be very useful if versionCode = $BITRISE_BUILD_NUMBER, but with this flow and using $BITRISE_BUILD_NUMBER app bundles versionCode is not sequential, with gaps and looks like: for example, 1.2.3(45), 1.2.3(52), 1.2.3(58).
That is confusing QA’s because of skipped range of numbers for versionCode.

Using Build Cache, Generic File Storage for storing variables in files, or editing app config files - are not preferable variants.

Hello Viktoria,

The build number is meant to be per project. An easy way to achieve this behaviour would be to split your project into two projects with one workflow each but it will be much harder to maintain them.

This is why I would recommend to implement a counter instead. You are right about trying to avoid managing and modifying files.

However, you can use one or more secrets to keep reference counts
https://api-docs.bitrise.io/#/secrets

For example, you can keep a secret
$BUNDLE_CREATION_REF and its content can be something like

{"workflow":"App bundle creation/Build", "reference":"[build_slug]", "counter", "1"}

Then, when you start a new App bundle creation/Build, you can fetch the currently running builds filtered by workflow with https://api-docs.bitrise.io/#/builds/build-list

You will get a list of builds. The counter of the current build will be equal to the counter of the reference build plus the number of builds from the build list between the reference build and the current build plus one. Then, you can update the reference build to be the current build and the reference counter to be the new counter.

Please note that if you use reference counters, you can avoid the problems associated with race conditions because you always receive the data from the builds endpoint in chronological order. Moreover, the reference build does not need to be the last build and the method will work even if the request to update the secret fails for whatever reason.

Ideally, this logic should be implemented in a Step.

I will also log the feature request for you. However, IMHO it is unlikely that this will be picked because the purpose of the build number is different from the purpose of a counter in your context.

Best!

1 Like