From 75a72b34cb9715295847f22144e8e62db8cb13b7 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 5 Dec 2016 16:10:33 -0800 Subject: [PATCH] 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@73146bb3b3248d545367c834471e7467ddc1a3e3 --- dev-tools/ci | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dev-tools/ci b/dev-tools/ci index 73f8c6b876e..09db5f66c6b 100755 --- a/dev-tools/ci +++ b/dev-tools/ci @@ -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"