Ubuntu – How to set version numbers and package file names via dpkg-buildpackge for automated builds on a build server

dpkgpackaging

Our build server builds ubuntu packages (*.deb) via dpkg-buildpackage. The server checks out the source code via git and runs the build via make <target>. The source directory contains the debian/ subdirectory where the dpkg configuration files are.

I would like to add the internal build counter number to the current package version and further set the package file name but dpkg-buildpackage does not let me control how the resulting package_version_arch.deb looks like. How can I achieve this?

Best Answer

Have a look at git-buildpackage:

Customizing snapshot numbers

If the auto incrementing of the snapshot number doesn't suite you needs you can give any python expression that evaluates to a positive integer to calculate the new snapshot number:

gbp dch -S -a --snapshot-number=1  
gbp dch -S -a --snapshot-number='snapshot + 2'
gbp dch -S -a --snapshot-number='os.popen("git-log --pretty=oneline | wc -l").readlines()[0]'
gbp dch -S -a --snapshot-number=`git-log --pretty=oneline debian/0.3.3 | wc -l`

You can also add the snapshot-number calculation to gbp.conf:

[DEFAULT]
snapshot-number = os.popen("git-log --pretty=oneline | wc -l").readlines()[0]