Browse Source

generate-git-snapshot: support $SKIP_BRANCH_AND_TAG_HANDLING and detect Gerrit pushes

If the GERRIT_REFSPEC variable is set then our job was triggered
via Gerrit Code Review [http://gerrit.googlecode.com/]. If that's
the case we don't want to modify the Git repository checkout by
branch or tag because we already have what we need inside
$GIT_COMMIT. Instead let's create the temporary branch based
on $GIT_COMMIT, otherwise (if we don't create a branch on our own)
we're lacking a branch and git-dch fails with:

| + git-dch --auto -S --multimaint-merge --ignore-branch --new-version=[...]
| fatal: ref HEAD is not a symbolic ref
| gbp:error: Currently not on a branch

Using a branch like [origin/]refs/changes/$ID/$ID/$PATCHSET when triggering
the *-source job using $branch setting from Gerrit fails, because
the ref isn't directly available for checkout as branch, but
Jenkins does the job for us so we can rely on $GIT_COMMIT.
tags/v0.11.0
Michael Prokop 7 years ago
parent
commit
017756fb40
1 changed files with 14 additions and 1 deletions
  1. +14
    -1
      scripts/generate-git-snapshot

+ 14
- 1
scripts/generate-git-snapshot View File

@@ -219,7 +219,20 @@ branch_checkout() {
# commit, so instead create a temporary branch to work on
random_branch="jenkins-debian-glue-buildbranch$RANDOM"

if [ -n "${tag:-}" ] && [ "${tag:-}" != "none" ] ; then
# skip branch building if the branch we received was triggered via gerrit
if [ -n "${GERRIT_REFSPEC:-}" ] ; then
echo "*** Setting SKIP_BRANCH_AND_TAG_HANDLING=true because we seem to be building for Gerrit ***"
SKIP_BRANCH_AND_TAG_HANDLING=true
fi

if [ "${SKIP_BRANCH_AND_TAG_HANDLING:-}" = "true" ] ; then
echo "*** Skipping branch/tag handling as requested via SKIP_BRANCH_AND_TAG_HANDLING ***"
echo "Making sure that random_branch $random_branch does not exist"
git branch -D "$random_branch" || true

echo "Checking out branch $random_branch based on git commit $GIT_COMMIT"
git checkout -b "$random_branch" "$GIT_COMMIT"
elif [ -n "${tag:-}" ] && [ "${tag:-}" != "none" ] ; then
echo "Making sure that random_branch $random_branch does not exist"
git branch -D "$random_branch" || true



Loading…
Cancel
Save