Build: Checkout relevant branch of elasticsearch for ci (elastic/elasticsearch#4270)

The ci script checks out elasticsearch for x-plugins to use. However, it
always checks out the master branch. This change makes the script look
for the source branch of a PR (falling back to GIT_BRANCH which is provided by jenkins for non PR CI jobs) and checks if that branch exists in elasticsearch. If it does not, it falls back to the target branch for the PR.

Original commit: elastic/x-pack-elasticsearch@73146bb3b3
This commit is contained in:
Ryan Ernst 2016-12-05 16:10:33 -08:00 committed by GitHub
parent ffeaea0663
commit 75a72b34cb
1 changed files with 15 additions and 3 deletions

View File

@ -2,7 +2,13 @@
# This script is used as a single command to run the x-plugins tests.
#
# It will attempt to check out 'elasticsearch' into a sibling directory
# unless the environment variable `USE_EXISTING_ES` has a value
# unless the environment variable `USE_EXISTING_ES` has a value. The
# branch of elasticsearch which will be checked out depends on
# environment variables. If running locally, set GIT_BRANCH. When
# running in Jenkins, that env var is set. When running a PR
# jenkins job, the variables PR_SOURCE_BRANCH and PR_TARGET_BRANCH
# will be set and the source branch will be looked for in elasticsearch
# before falling back to the target branch name.
#
# It will also attempt to install the appropriate version of node.js
# for the Kibana plugin tests using nvm, unless
@ -62,8 +68,14 @@ if [ -z ${USE_EXISTING_ES:+x} ]; then
echo "Either define 'USE_EXISTING_ES' or remove the existing 'elasticsearch' sibling."
exit 1
fi
echo "Checking out Elasticsearch 'master' branch..."
git clone https://github.com/elastic/elasticsearch.git --depth=1
BRANCH=${PR_SOURCE_BRANCH:-$GIT_BRANCH} # fall back to CI branch if not testing a PR
echo "Checking if branch '$BRANCH' has elasticsearch sibling..."
if [[ -z "$(git ls-remote --heads git@github.com:elastic/elasticsearch.git $BRANCH)" ]]; then
echo "No sibling branch, using PR target branch"
BRANCH=$PR_TARGET_BRANCH
fi
echo "Checking out Elasticsearch '$BRANCH' branch..."
git clone -b $BRANCH https://github.com/elastic/elasticsearch.git --depth=1
else
if [ -d "./elasticsearch" ]; then
echo "Using existing 'elasticsearch' checkout"