[ci] Allow schedule to trigger several pipelines (#15703)

This commit enhances the functionality introduced in #15668 and #15700
by allowing a single Buildkite scheduling job to trigger several
pipelines, in addition to multiple branches which it already does.

We rename the env var PIPELINE_TO_TRIGGER to PIPELINES_TO_TRIGGER
which now supports comma separate values.

This enhancement can be useful for pipelines like JDK matrix which
have variants (Linux and Windows) that we want to trigger with a single
scheduling job, thus reducing unnecessary entries in catalog-info.
This commit is contained in:
Dimitrios Liappis 2023-12-20 10:22:46 +02:00 committed by GitHub
parent 42497edebb
commit 06ceef8e13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View file

@ -22,13 +22,19 @@ if ! [[ -x $(which yq) && $(yq --version) == *mikefarah* ]]; then
fi fi
} }
if [[ -z $PIPELINE_TO_TRIGGER ]]; then function parse_pipelines() {
IFS="," read -ra PIPELINES <<< "$PIPELINES_TO_TRIGGER"
}
if [[ -z $PIPELINES_TO_TRIGGER ]]; then
echo "^^^ +++" echo "^^^ +++"
echo "Required environment variable [PIPELINE_TO_TRIGGER] is missing." echo "Required environment variable [PIPELINES_TO_TRIGGER] is missing."
echo "Exiting now." echo "Exiting now."
exit 1 exit 1
fi fi
parse_pipelines
set -u set -u
set +e set +e
BRANCHES=$(curl --retry-all-errors --retry 5 --retry-delay 5 -fsSL $ACTIVE_BRANCHES_URL | jq -r '.branches[].branch') BRANCHES=$(curl --retry-all-errors --retry 5 --retry-delay 5 -fsSL $ACTIVE_BRANCHES_URL | jq -r '.branches[].branch')
@ -43,15 +49,17 @@ install_yq
echo 'steps:' >pipeline_steps.yaml echo 'steps:' >pipeline_steps.yaml
for PIPELINE in "${PIPELINES[@]}"; do
for BRANCH in $BRANCHES; do for BRANCH in $BRANCHES; do
cat >>pipeline_steps.yaml <<EOF cat >>pipeline_steps.yaml <<EOF
- trigger: $PIPELINE_TO_TRIGGER - trigger: $PIPELINE
label: ":testexecute: Triggering ${PIPELINE_TO_TRIGGER} / ${BRANCH}" label: ":testexecute: Triggering ${PIPELINE} / ${BRANCH}"
build: build:
branch: "$BRANCH" branch: "$BRANCH"
message: ":testexecute: Scheduled build for ${BRANCH}" message: ":testexecute: Scheduled build for ${BRANCH}"
EOF EOF
done done
done
echo "--- Printing generated steps" echo "--- Printing generated steps"
yq . pipeline_steps.yaml yq . pipeline_steps.yaml

View file

@ -1,5 +1,5 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json # yaml-language-server: $schema=https://raw.githubusercontent.com/buildkite/pipeline-schema/main/schema.json
steps: steps:
- label: ":pipeline: Generate trigger steps for $PIPELINE_TO_TRIGGER" - label: ":pipeline: Generate trigger steps for $PIPELINES_TO_TRIGGER"
command: ".buildkite/scripts/common/trigger-pipeline-generate-steps.sh" command: ".buildkite/scripts/common/trigger-pipeline-generate-steps.sh"

View file

@ -185,7 +185,7 @@ spec:
description: ':alarm_clock: Scheduled runs of Logstash DRA Snapshot Pipeline per eligible branch' description: ':alarm_clock: Scheduled runs of Logstash DRA Snapshot Pipeline per eligible branch'
spec: spec:
repository: elastic/logstash repository: elastic/logstash
pipeline_file: ".buildkite/trigger_pipeline.yml" pipeline_file: ".buildkite/trigger_pipelines.yml"
maximum_timeout_in_minutes: 120 maximum_timeout_in_minutes: 120
schedules: schedules:
Daily main: Daily main:
@ -196,7 +196,7 @@ spec:
provider_settings: provider_settings:
trigger_mode: none trigger_mode: none
env: env:
PIPELINE_TO_TRIGGER: 'logstash-dra-snapshot-pipeline' PIPELINES_TO_TRIGGER: 'logstash-dra-snapshot-pipeline'
ELASTIC_SLACK_NOTIFICATIONS_ENABLED: 'true' ELASTIC_SLACK_NOTIFICATIONS_ENABLED: 'true'
SLACK_NOTIFICATIONS_CHANNEL: '#logstash' SLACK_NOTIFICATIONS_CHANNEL: '#logstash'
SLACK_NOTIFICATIONS_ON_SUCCESS: 'false' SLACK_NOTIFICATIONS_ON_SUCCESS: 'false'