Set a new value for the Pipelines build number

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Updating the Pipelines build number

You can use the Bitbucket REST API to set the Pipelines build number $BITBUCKET_BUILD_NUMBER to a higher value. You might want to do this if you are moving from another build tool where you already have built versions of your software with a higher build number.

Steps

  1. Log in to Bitbucket and go to Bitbucket settings > App passwords via the user menu.
  2. Create a new app password with permission to "edit variables" in Pipelines. Copy the new password to your clipboard.
  3. Use curl to PUT to the Pipelines build_number config API:
curl -v -H 'Content-Type: application/json' -XPUT \
  -d '{ "next": 1000 }' \
  --user 'USERNAME:PASSWORD' \
  'https://api.bitbucket.org/2.0/repositories/USERNAME/REPONAME/pipelines_config/build_number'

In the example above, you will need to replace:

  • 1000 with the next desired build number
  • USERNAME with your Bitbucket username (note there are two instances of USERNAME in the command)
  • PASSWORD with the app password you generated and copied above
  • REPONAME with the slug of your repository.

If it worked correctly, Bitbucket will respond with the following:

{"type": "pipeline_build_number", "next": 1000}

The next Pipelines build you run will use this as its build number.

Error responses

Potential error responses include:

  • HTTP/1.1 401 Unauthorized – this comes back as an HTTP header if Bitbucket cannot identify your username. Make sure you update the command above to have the correct username in both the URL and --user parameter.
  • Your credentials lack one or more required privilege scopes – you need to ensure your app password has the permission to edit Pipelines variables.
  • An invalid field was found in the JSON payload – you need to ensure your JSON payload matches the format above, a single object with a next field with an integer value (type is optional).
  • The request body contains invalid properties - your build number is lower than existing builds in Pipelines.

Limitations

There is no way to update the build number through the Bitbucket web UI. This change is only possible through the Bitbucket REST API.

You cannot set the build number to a number that is lower than any existing build result in the repository. It is not currently possible to delete Pipelines builds, so we need to ensure the future build number will not clash with any existing build.

 

Last modified on Aug 21, 2017

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.