Build number that increments on every build

Issue #12838 resolved
CarePay Limited
created an issue

We would like to have an environment variable which contains the build number for the current branch. The build number should increment every time pipeline is executed.

This would allow us to create unique artifacts names, like we had in Bamboo.

Official response

  • Matt Ryall staff

    I'm happy to let you know that we've shipped $BITBUCKET_BUILD_NUMBER – an incrementing build number for each build in your repository that is available as an environment variable. All previous builds have been numbered as well, and you'll see the new number appearing in your Pipelines UI.

    A few neat things about this feature:

    • $BITBUCKET_BUILD_NUMBER values will be unique across all branches, meaning you can use it as a software build number that won't clash with builds on other branches
    • rerunning a build will give it a new build number, also avoiding clashes and helping you track reruns better in the list of completed builds
    • you can increment the build number to a new starting point using our REST API, which is handy if you're moving from another tool.

    Note that this feature doesn't aim to provide semantic versioning or branch-specific version numbers (i.e. version numbers for humans). You can find other tools out there that will do this for you, like the wonderful semantic-release.

    Thanks for your feedback on this ticket and your continued support of Bitbucket Pipelines!

Comments (31)

  1. Colin Hebert

    One quick and easy solution to obtain unique artifact names is to go with the commit id. You lose the ordering system by doing so, but uniqueness is respected, and you get to easily identify which build is from which commit. A way to obtain incrementing IDs for a branch, is to use the branch name and the current timestamp, in guarantees that the artifacts can be sorted by creation date for a given branch.

  2. CarePay Limited reporter

    As a workaround for now, we've implemented a Gradle plugin which deploys to Amazon's ElasticBeanStalk. The plugin retrieves the current version deployed, and increments that by one. Still, all competing buildservers (Jenkens, Bamboo, etc) have support for a decimal buildnumber which increases on each build.

  3. Alex Soto

    I have multiple branches triggering pipeline builds with the same SHA (eg: master => integration branch promotion).

    The build/statuses API response therefore has two build status records for the same SHA (one for each branch). There is no way to 'know' the build key to lookup so you can't programmatically determine which build status record is for which branch!

    At this time, the pipelines build/status description field does contain the branch name, but having to parse the branch out of description is not a 'good' solution you can depend on. It would be more precise if we already knew the build id/key at build time, so we can store that metadata and reference it later in other processes/scripts.

  4. Matt Ryall staff

    I'm happy to let you know that we've shipped $BITBUCKET_BUILD_NUMBER – an incrementing build number for each build in your repository that is available as an environment variable. All previous builds have been numbered as well, and you'll see the new number appearing in your Pipelines UI.

    A few neat things about this feature:

    • $BITBUCKET_BUILD_NUMBER values will be unique across all branches, meaning you can use it as a software build number that won't clash with builds on other branches
    • rerunning a build will give it a new build number, also avoiding clashes and helping you track reruns better in the list of completed builds
    • you can increment the build number to a new starting point using our REST API, which is handy if you're moving from another tool.

    Note that this feature doesn't aim to provide semantic versioning or branch-specific version numbers (i.e. version numbers for humans). You can find other tools out there that will do this for you, like the wonderful semantic-release.

    Thanks for your feedback on this ticket and your continued support of Bitbucket Pipelines!

  5. Log in to comment