build-unit-test-docker: use Gerrit revision if available
If Jenkins is triggering us to run CI on a package that is included
in the Docker image itself, use the requested revision-under-test as
part of the Docker image build process.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I61a0a249123800aba860ab1535e96f5cdb2ec63f
diff --git a/scripts/build-unit-test-docker b/scripts/build-unit-test-docker
index 38a4508..ae34417 100755
--- a/scripts/build-unit-test-docker
+++ b/scripts/build-unit-test-docker
@@ -421,6 +421,15 @@
if "rev" in self.pkg_def:
return
+ # Check if Jenkins/Gerrit gave us a revision and use it.
+ if gerrit_project == self.package and gerrit_rev:
+ print(
+ f"Found Gerrit revision for {self.package}: {gerrit_rev}",
+ file=sys.stderr,
+ )
+ self.pkg_def["rev"] = gerrit_rev
+ return
+
# Ask Github for all the branches.
lookup = git("ls-remote", "--heads", f"https://github.com/{self.package}")
@@ -635,6 +644,9 @@
ubuntu_mirror = os.environ.get("UBUNTU_MIRROR")
http_proxy = os.environ.get("http_proxy")
+gerrit_project = os.environ.get("GERRIT_PROJECT")
+gerrit_rev = os.environ.get("GERRIT_PATCHSET_REVISION")
+
# Set up some common variables.
username = os.environ.get("USER", "root")
homedir = os.environ.get("HOME", "/root")