Skip to content

Commit 603b85d

Browse files
committed
try leaking a secret
1 parent 02f0579 commit 603b85d

File tree

4 files changed

+72
-14
lines changed

4 files changed

+72
-14
lines changed

.buildkite/build_pr_pipeline.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
steps:
22
- key: "build-pr-setup"
33
label: "setup"
4-
command: .buildkite/scripts/build_pr_setup.sh
4+
command: ".buildkite/scripts/build_pr_commit_status.sh pending 'Build started'"
55
- key: "build-pr"
66
label: ":hammer: Build docs PR"
7-
command: |
8-
bash .buildkite/scripts/build_pr.sh
7+
command: echo 'hello' #".buildkite/scripts/build_pr.sh"
98
depends_on:
109
- step: build-pr-setup
1110
allow_failure: true
1211
agents:
1312
provider: "gcp"
1413
image: family/docs-ubuntu-2204
15-
- command: ".buildkite/scripts/build_pr_teardown.sh || true"
14+
- command: ".buildkite/scripts/build_pr_commit_status.sh || true"
1615
label: "teardown"
16+
command: |
17+
if [ $(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then
18+
.buildkite/scripts/build_pr_commit_status.sh 'success' 'Build finished'
19+
else
20+
.buildkite/scripts/build_pr_commit_status.sh 'failure' 'Build finished'
21+
fi
1722
depends_on:
1823
- step: "build-pr"
19-
allow_failure: true

.buildkite/hooks/pre-command

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
function retry {
6+
local retries=$1
7+
shift
8+
9+
local count=0
10+
until "$@"; do
11+
exit=$?
12+
wait=$((2 ** count))
13+
count=$((count + 1))
14+
if [ $count -lt "$retries" ]; then
15+
>&2 echo "Retry $count/$retries exited $exit, retrying in $wait seconds..."
16+
sleep $wait
17+
else
18+
>&2 echo "Retry $count/$retries exited $exit, no more retries left."
19+
return $exit
20+
fi
21+
done
22+
return 0
23+
}
24+
25+
# Secrets must be redacted
26+
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
27+
if [[ "$BUILDKITE_PIPELINE_SLUG" == "docs-build-pr" ]];then
28+
export GITHUB_TOKEN=$(retry 5 vault kv get -field=value secret/ci/elastic-docs/docs_preview_cleaner)
29+
fi

.buildkite/scripts/build_pr_teardown.sh renamed to .buildkite/scripts/build_pr_commit_status.sh

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,34 @@ set -euo pipefail
66
if [ -z ${GITHUB_PR_OWNER+set} ] || [ -z ${GITHUB_PR_REPO+set} ] || [ -z ${GITHUB_PR_TRIGGERED_SHA+set} ];then
77
exit 0
88
fi
9-
exit 1
10-
gitHubToken=$(vault read -field=value secret/ci/elastic-docs/docs_preview_cleaner)
119

12-
if [ $(buildkite-agent step get "outcome" --step "build-pr") == "passed" ]; then
13-
status_state="success"
14-
else
15-
status_state="failure"
10+
11+
if [ $# -lt 2 ]; then
12+
echo "Usage: $0 <state> <description>"
13+
exit 1
1614
fi
1715

16+
status_state=$1
17+
description=$2
18+
19+
case $status_state in
20+
pending|success|failure|error)
21+
echo "Setting buildkite/docs commit status to ${status_state}";;
22+
*)
23+
echo "Invalid state"
24+
exit 1;;
25+
esac
26+
set -x
27+
echo "The value of my secret is $MY_SECRET"
28+
1829
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/'$BUILDKITE_PIPELINE_SLUG'"}'
20-
echo "Setting buildkite/docs commit status to ${status_state}"
30+
31+
data='{"state":"'$status_state'","target_url":"'$BUILDKITE_BUILD_URL'","description":"'$description'","context":"buildkite/'$BUILDKITE_PIPELINE_SLUG'"}'
32+
2133
curl -s -L \
2234
-X POST \
2335
-H "Accept: application/vnd.github+json" \
24-
-H "Authorization: Bearer ${gitHubToken}" \
36+
-H "Authorization: Bearer ${GITHUB_TOKEN}" \
2537
-H "X-GitHub-Api-Version: 2022-11-28" \
2638
"${githubPublishStatus}" \
2739
-d "${data}"

.buildkite/scripts/build_pr_setup.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
set -euo pipefail
44

5+
echo "The value is $MY_SECRET"
6+
7+
state=$(buildkite-agent step get "state" --step "build-pr-setup")
8+
echo "State of build-pr-setup is $state"
9+
10+
state=$(buildkite-agent step get "outcome" --step "build-pr-setup")
11+
echo "outcome of build-pr-setup is $state"
12+
13+
state=$(buildkite-agent step get "state" --step "build-pr")
14+
echo "State is $state"
15+
16+
state=$(buildkite-agent step get "outcome" --step "build-pr")
17+
echo "outcome of build-pr is $state"
518
# Configure the git author and committer information
619
export GIT_AUTHOR_NAME='Buildkite CI'
720
export GIT_AUTHOR_EMAIL='[email protected]'

0 commit comments

Comments
 (0)