diff --git a/buildjob b/buildjob
index 41d437ff09b797cae6fe6ebbb4297ab4dc5280f4..216308c04907e5b865fb4de34e39e49ff7535221 100755
--- a/buildjob
+++ b/buildjob
@@ -3,12 +3,10 @@ set -e
 #set -x
 
 ## This runs a default build job.  The following variables are noteworthy:
-## - $MAIN_BRANCH: The "main branch" this current branch comes from (usually
-##   master)
 ## - $OPAM_PINS: Space-separated list of packages to pin in opam, in the format
 ##   "PACKAGE KIND TARGET   PACKAGE KIND TARGET   ..."
 ## - $VALIDATE: If non-empty, run `make validate`
-## - $OPAM_PKG, $OPAM_UPDATE_SECRET: IF $OPAM_PKG is
+## - $OPAM_PKG, $OPAM_UPDATE_SECRET, $OPAM_PKG_BRANCH: IF $OPAM_PKG is
 ##   non-empty, release this commit as a new package on opam when done.
 ##   Requires the $OPAM_UPDATE_SECRET variable to be set.  This only happens if
 ##   the current branch is $OPAM_PKG_BRANCH, or master if that variable is
@@ -55,7 +53,7 @@ if [[ -n "$TIMING_PROJECT" && -n "$TIMING_CONF" ]]; then
 fi
 
 # maybe create opam package
-if [[ -n "$OPAM_PKG" && "$CI_COMMIT_REF_NAME" == "$MAIN_BRANCH" ]]; then
+if [[ -n "$OPAM_PKG" && "$CI_COMMIT_REF_NAME" == "${OPAM_PKG_BRANCH:-master}" ]]; then
     echo_color "$BOLDGREEN" "[buildjob] Releasing package on opam"
     # check if we have the secret
     if [[ -z "$OPAM_UPDATE_SECRET" ]]; then