From e8cf9b7f05618c9006c19766c2a8e18371d3e5b2 Mon Sep 17 00:00:00 2001 From: Mariusz Jozala Date: Thu, 24 Apr 2025 10:50:38 +0200 Subject: [PATCH] [CI] Add branch filtering logic to DRA trigger pipeline This filtering will be used to trigger DRA for 7.17 weekly instead of twice a day. --- .buildkite/scripts/dra-workflow.trigger.sh | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/.buildkite/scripts/dra-workflow.trigger.sh b/.buildkite/scripts/dra-workflow.trigger.sh index ad691281b887a..d8bb624588191 100755 --- a/.buildkite/scripts/dra-workflow.trigger.sh +++ b/.buildkite/scripts/dra-workflow.trigger.sh @@ -2,10 +2,34 @@ set -euo pipefail -echo "steps:" - source .buildkite/scripts/branches.sh +# We use that filtering to keep different schedule for different branches +if [ -n "${INCLUDED_BRANCHES:-}" ]; then + # If set, only trigger the pipeline for the specified branches + IFS=',' read -r -a BRANCHES <<< "${INCLUDED_BRANCHES}" +elif [ -n "${EXCLUDED_BRANCHES:-}" ]; then + # If set, listed branches will be excluded from the list of branches in branches.json + IFS=',' read -r -a EXCLUDED_BRANCHES <<< "${EXCLUDED_BRANCHES}" + FILTERED_BRANCHES=() + for BRANCH in "${BRANCHES[@]}"; do + EXCLUDE=false + for EXCLUDED_BRANCH in "${EXCLUDED_BRANCHES[@]}"; do + if [ "$BRANCH" == "$EXCLUDED_BRANCH" ]; then + EXCLUDE=true + break + fi + done + if [ "$EXCLUDE" = false ]; then + FILTERED_BRANCHES+=("$BRANCH") + fi + done + BRANCHES=("${FILTERED_BRANCHES[@]}") +fi + + +echo "steps:" + for BRANCH in "${BRANCHES[@]}"; do INTAKE_PIPELINE_SLUG="elasticsearch-intake" BUILD_JSON=$(curl -sH "Authorization: Bearer ${BUILDKITE_API_TOKEN}" "https://api.buildkite.com/v2/organizations/elastic/pipelines/${INTAKE_PIPELINE_SLUG}/builds?branch=${BRANCH}&state=passed&per_page=1" | jq '.[0] | {commit: .commit, url: .web_url}')