Skip to content

Commit da0d722

Browse files
committed
Switch buildkite hooks to pipeline steps
This is a more explicit approach that can be applied to the PR pipeline only and allows to run only once before/after the build, as opposed to the pre/post command hooks that run for every command.
1 parent 126758b commit da0d722

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.buildkite/build_pr_pipeline.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
steps:
2-
- label: ":white_check_mark: Build docs PR"
3-
command: |
4-
bash .buildkite/scripts/build_pr.sh
2+
- key: "build-pr-setup"
3+
label: "setup"
4+
command: .buildkite/scripts/build_pr_setup.sh
5+
- key: "build-pr"
6+
label: ":hammer: Build docs PR"
7+
command: .buildkite/scripts/build_pr.sh
8+
depends_on:
9+
- step: build-pr-setup
10+
allow_failure: true
511
agents:
612
provider: "gcp"
713
image: family/docs-ubuntu-2204
14+
- command: .buildkite/scripts/build_pr_teardown.sh
15+
label: "teardown"
16+
depends_on:
17+
- step: "build-pr"
18+
allow_failure: true

.buildkite/hooks/pre-command renamed to .buildkite/scripts/build_pr_setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fi
1616
gitHubToken=$(vault read -field=value secret/ci/elastic-docs/docs_preview_cleaner)
1717

1818
githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_OWNER}/${GITHUB_PR_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}"
19-
data='{"state":"pending","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build started.","context":"buildkite/docs"}'
19+
data='{"state":"pending","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build started.","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}'
2020
echo "Setting buildkite/docs commit status to pending"
2121
curl -s -L \
2222
-X POST \

.buildkite/hooks/post-command renamed to .buildkite/scripts/build_pr_teardown.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ fi
99

1010
gitHubToken=$(vault read -field=value secret/ci/elastic-docs/docs_preview_cleaner)
1111

12-
if [ -n "$BUILDKITE_COMMAND_EXIT_STATUS" ] && [ "$BUILDKITE_COMMAND_EXIT_STATUS" -eq "0" ];then
12+
if [ $(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then
1313
status_state="success"
1414
else
1515
status_state="failure"
1616
fi
1717

1818
githubPublishStatus="https://api.github.com/repos/${GITHUB_PR_OWNER}/${GITHUB_PR_REPO}/statuses/${GITHUB_PR_TRIGGERED_SHA}"
19-
data='{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished.","context":"buildkite/docs"}'
19+
data='{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"Build finished.","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}'
2020
echo "Setting buildkite/docs commit status to ${status_state}"
2121
curl -s -L \
2222
-X POST \

0 commit comments

Comments
 (0)