diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command index 67580d63901..282fb5a0085 100644 --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -2,10 +2,27 @@ set -euo pipefail -source .buildkite/scripts/common.sh - AWS_SERVICE_ACCOUNT_SECRET_PATH="kv/ci-shared/platform-ingest/aws_account_auth" +retry() { + local retries=$1 + shift + local count=0 + until "$@"; do + exit=$? + wait=$((2 ** count)) + count=$((count + 1)) + if [ $count -lt "$retries" ]; then + >&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." + sleep $wait + else + >&2 echo "Retry $count/$retries exited $exit, no more retries left." + return $exit + fi + done + return 0 +} + if [[ "$BUILDKITE_PIPELINE_SLUG" == "filebeat" || "$BUILDKITE_PIPELINE_SLUG" == "auditbeat" || "$BUILDKITE_PIPELINE_SLUG" == "heartbeat" ]]; then source .buildkite/env-scripts/env.sh source .buildkite/env-scripts/util.sh @@ -24,19 +41,9 @@ if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-metricbeat" || "$BUILDKITE_PIPELINE_S fi fi -if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" ]]; then - if [[ "${BUILDKITE_STEP_KEY}" == "mandatory-int-test" || "${BUILDKITE_STEP_KEY}" == "mandatory-python-int-test" || "${BUILDKITE_STEP_KEY}" == "extended-cloud-test" ]]; then - # Configure MODULE env variable. - defineModuleFromTheChangeSet "${MODULE_DIR}" - fi - if [[ "${BUILDKITE_STEP_KEY}" == "extended-cloud-test" ]]; then - # Start the required services for the required - startCloudTestEnv "${MODULE_DIR}" - - # export AWS masked credentials - BEATS_AWS_SECRET_KEY=$(retry 5 vault kv get -field secret_key ${AWS_SERVICE_ACCOUNT_SECRET_PATH}) - export BEATS_AWS_SECRET_KEY - BEATS_AWS_ACCESS_KEY=$(retry 5 vault kv get -field access_key ${AWS_SERVICE_ACCOUNT_SECRET_PATH}) - export BEATS_AWS_ACCESS_KEY - fi +if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" && "$BUILDKITE_STEP_KEY" == "extended-cloud-test" ]]; then + BEATS_AWS_SECRET_KEY=$(retry 5 vault kv get -field secret_key ${AWS_SERVICE_ACCOUNT_SECRET_PATH}) + export BEATS_AWS_SECRET_KEY + BEATS_AWS_ACCESS_KEY=$(retry 5 vault kv get -field access_key ${AWS_SERVICE_ACCOUNT_SECRET_PATH}) + export BEATS_AWS_ACCESS_KEY fi diff --git a/.buildkite/scripts/common.sh b/.buildkite/scripts/common.sh index 4d702f58615..ec2908e997b 100755 --- a/.buildkite/scripts/common.sh +++ b/.buildkite/scripts/common.sh @@ -484,4 +484,8 @@ if are_paths_changed "${packaging_changeset[@]}" ; then export PACKAGING_CHANGES="true" fi +if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" ]]; then + defineModuleFromTheChangeSet "${MODULE_DIR}" +fi + check_and_set_beat_vars diff --git a/.buildkite/scripts/install_tools.sh b/.buildkite/scripts/install_tools.sh index 80e70ae96c5..a7a2787e4f4 100755 --- a/.buildkite/scripts/install_tools.sh +++ b/.buildkite/scripts/install_tools.sh @@ -43,6 +43,10 @@ with_dependencies config_git mage dumpVariables +if [[ "$BUILDKITE_PIPELINE_SLUG" == "beats-xpack-metricbeat" && "${BUILDKITE_STEP_KEY}" == "extended-cloud-test" ]]; then + startCloudTestEnv "${MODULE_DIR}" +fi + #sudo command doesn't work at the "pre-command" hook because of another user environment (root with strange permissions) sudo chmod -R go-w "${BEATS_PROJECT_NAME}/" #TODO: Remove when the issue is solved https://github.com/elastic/beats/issues/37838