简体   繁体   中英

How do I detect that gerrit change needs rebasing on Jenkins?

I want to fail-fast on Gerrit triggered Jenkins jobs when the changes are outdated and they need rebasing by adding a piece of code at the start of the job that triggers and error: "Rebase your change first."

You can find the list of Jenkins variables defined by Gerrit plugin at What environment variables are passed go Jenkins when using the Gerrit Trigger Plugin?

This broken attempt:

#!/bin/bash
set -exo pipefail
# fast-fail if gerrit change is not rebased
if [ -z ${GERRIT_PROJECT+x} ]; then
  pushd $GERRIT_PROJECT
    MERGE_BASE=$(git merge-base HEAD origin/$GERRIT_BRANCH)
    git rebase
    [ "$MERGE_BASE" == "$(git merge-base HEAD origin/$GERRIT_BRANCH)" ] || {
      echo "FATAL:  Please rebase $GERRIT_CHANGE_URL change request before testing it."
      exit 101
    }
  popd
fi

Somehow this worked on some jobs using pipelines but failed on others, I suspect due to a different checkout method. So, still looking for a reliable way of doing it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM