It's possible to add user-defined fields in the debian/control file using the XBS-
method, as defined in the Debian Policy Manual, and those will be injected into the binary .deb and source packages.
Something like this before calling dpkg-buildpackage will work to inject a new field into both the Source and Binary packages. But some packages don't contain debian/control as they generate it (kernel etc) so this is not always reliable.
sed -i "0,/^\s*$/s//XBS-Git-Branch: ${CI_COMMIT_BRANCH}\n/" debian/control
dpkg-buildpackage
It's also possible to inject the user-defined field into the generated source package using options passed to dpkg-source while building the package:
dpkg-buildpackage --source-option=-DGit-Branch=${CI_COMMIT_BRANCH}
However, that will only inject the field into the generated source package, not the generated binary packages. Is there a method to reliably inject fields into the binary packages?