Skip to content

Instantly share code, notes, and snippets.

@ochaloup
Created April 28, 2024 06:05
Show Gist options
  • Save ochaloup/8489c152d86bad73a084c8b8b5862f61 to your computer and use it in GitHub Desktop.
Save ochaloup/8489c152d86bad73a084c8b8b5862f61 to your computer and use it in GitHub Desktop.
Buildkite script managing upload artifacts and failures
agents:
queue: "snapshots"
steps:
- label: ":mega: Notification setup"
commands:
- 'notification_color="8388863"'
- 'buildkite-agent meta-data set notification_color "$$notification_color"'
- |
epoch=333
echo "$$DISCORD_WEBHOOK_VALIDATOR_BONDS" -H "Content-Type: application/json" -d '{
"embeds": [
{
"title": "Initializing Settlements for Validator Bonds ('"$$epoch"').",
"url": "'"$$BUILDKITE_BUILD_URL"'",
"color": "'"$$notification_color"'"
}
]
}'
- label: "Build and Test"
commands:
- 'prior_build_number=$(($$BUILDKITE_RETRY_COUNT - 1))'
- 'buildkite-agent artifact download --include-retried-jobs build-report.$$prior_build_number . || true'
- 'echo "This is attempt number $$BUILDKITE_RETRY_COUNT"'
- |
cp "build-report.$$prior_build_number" "build-report.$$BUILDKITE_RETRY_COUNT" || true
rm -f "build-report.$$prior_build_number"
- 'echo "#ATTEMPT $$BUILDKITE_RETRY_COUNT" | tee -a "./build-report.$$BUILDKITE_RETRY_COUNT"'
- 'echo "-- something something --" | tee -a "./build-report.$$BUILDKITE_RETRY_COUNT"'
- '[ $$BUILDKITE_RETRY_COUNT -lt 3 ] && exit 1 || echo OK'
# - 'buildkite-agent artifact upload --include-retried-jobs "build-report.$$BUILDKITE_RETRY_COUNT" .'
# https://buildkite.com/docs/pipelines/command-step#retry-attributes
retry:
automatic:
- exit_status: '*'
limit: 2
key: "build-and-test"
artifact_paths:
- "./build-report.*"
# # This property causes the pipeline to be aborted if this step fails(?)
# soft_fail: false
- label: "Notification result and color step"
commands:
- 'echo "Build and Test succeeded, running color setup step"'
- 'build_result=$(buildkite-agent step get "outcome" --step "build-and-test")'
- |
if [[ "$$build_result" =~ "failed" ]]; then
notification_result="FAILED"
notification_color="15158332"
else
notification_result="SUCCEEDED"
notification_color=$(buildkite-agent meta-data get notification_color)
fi
- 'buildkite-agent meta-data set notification_color "$$notification_color"'
- 'buildkite-agent meta-data set notification_result "$$notification_result"'
- 'echo "Notification result: $$notification_result, Notification color: $$notification_color"'
depends_on: "build-and-test"
allow_dependency_failure: true
- wait: ~
continue_on_failure: true
- label: "Notification"
commands:
- 'echo Notification step'
- 'mkdir ./reports'
- 'buildkite-agent artifact download --include-retried-jobs "build-report.*" ./reports/'
- 'report_path="./reports/$(ls -v1 reports/ | tail -n 1)"'
# - 'gcloud storage cp "$$report_path" "$$gs_bucket/$$epoch/"'
- 'attempts_count=$(grep -c "#ATTEMPT" "$$report_path")'
- 'report=$(cat "$$report_path")'
- 'notification_result=$(buildkite-agent meta-data get notification_result)'
- 'notification_color=$(buildkite-agent meta-data get notification_color)'
- |
echo "$$DISCORD_WEBHOOK_VALIDATOR_BONDS" -H "Content-Type: application/json" -d '{
"embeds": [
{
"title": "Initializing Settlements for Validator Bonds ('"$$epoch"') '"$$notification_result"' after '"$$attempts_count"' attempts.",
"url": "'"$$BUILDKITE_BUILD_URL"'",
"color": "'"$$notification_color"'"
}
],
"content": ("```\n'"$$report"'```"),
"attachments": []
}'
- wait: ~
- label: "Only when succeeded"
command: "echo 'Everything succeeded, hey!'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment