4

I'm trying to integrate building of a wheel file into a Bamboo plan. Ultimately, I'd like to tie part of the version tag of the .whl file to the Bamboo build number in someway, i.e. the pre-release for version 0 would be 0.dev1, 0.dev2, 0.dev3 for successive builds.

The old egg format used to allow the --tag_build option, which would allow you to specify a tag that is appended to the version parameter defined in the setup function in the setup.py file. The bdist_wheel command apparently doesn't have an equivalent option.

This dashed my hopes of running setup.py from a script, using the Bamboo build number variable. I'm looking for any other suggestions other than either converting the build script to Powershell, or generating setup.py on the fly each build.

TWReever
  • 357
  • 4
  • 14

1 Answers1

7

The version tag in the wheel filename is just the package version number, defined by setup.py, and setup.py is a Python script with all the power of Python available to it. Thus, setup.py can simply set the version parameter of the setup() function based on the bamboo_buildNumber environment variable:

import os

version = whatever_the_version_would_be_otherwise
try:
    version += '.dev' + os.environ['bamboo_buildNumber']
except KeyError:  # bamboo_buildNumber isn't defined, so we're not running in Bamboo
    pass

setup(
    version = version,
    ...
)
jwodder
  • 54,758
  • 12
  • 108
  • 124
  • thanks for the answer! This was my first attempt to add a plan to a project in Bamboo and I hadn't found all the documentation for the env variables it sets yet. – TWReever Dec 14 '16 at 19:29
  • Do you know of a way to do this with either the setup.cfg or command line parameters? – rstackhouse Sep 19 '17 at 16:58