Skip to content

Commit 69f3a8b

Browse files
authored
[CI] Use buildkite plugin to set github token (#935)
Use https://github.com/elastic/vault-github-token-buildkite-plugin instead of using pre-command hooks with complicated conditions. This helps to know what Buildkite step uses VAULT_GITHUB_TOKEN and self-document those sensitive details as it's a declarative syntax.
1 parent 0d6f54c commit 69f3a8b

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

.buildkite/hooks/pre-command

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@ source .buildkite/scripts/tooling.sh
44

55
set -euo pipefail
66

7-
GO_VERSION=$(cat .go-version)
8-
export GO_VERSION
9-
107
# Secrets must be redacted
118
# https://buildkite.com/docs/pipelines/managing-log-output#redacted-environment-variables
129

13-
if [[ "$BUILDKITE_PIPELINE_SLUG" == "package-spec-test-with-integrations" && "$BUILDKITE_STEP_KEY" == "pr-integrations" ]]; then
14-
# required to set the git commit information
15-
GITHUB_USERNAME_SECRET="elasticmachine"
16-
export GITHUB_USERNAME_SECRET=$GITHUB_USERNAME_SECRET
17-
export GITHUB_EMAIL_SECRET="elasticmachine@elastic.co"
18-
# required by `gh` commands
19-
export GITHUB_TOKEN=$VAULT_GITHUB_TOKEN
20-
fi
10+
GO_VERSION=$(cat .go-version)
11+
export GO_VERSION

.buildkite/pipeline.test-with-integrations-repo.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ steps:
2626
- label: ":hammer: Create PR in integrations"
2727
key: pr-integrations
2828
command: ".buildkite/scripts/test-with-integrations.sh"
29+
env:
30+
GITHUB_EMAIL: "elasticmachine@elastic.co"
31+
GITHUB_USERNAME: "elastic-vault-github-plugin-prod"
32+
plugins:
33+
# Required to push branches, create PRs and post comments on PRs
34+
- elastic/vault-github-token#v0.1.0:
2935
agents:
3036
provider: "gcp"
3137
depends_on:

.buildkite/scripts/test-with-integrations.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ get_source_commit_link() {
5454
}
5555

5656
set_git_config() {
57-
git config user.name "${GITHUB_USERNAME_SECRET}"
58-
git config user.email "${GITHUB_EMAIL_SECRET}"
57+
git config user.name "${GITHUB_USERNAME}"
58+
git config user.email "${GITHUB_EMAIL}"
5959
}
6060

6161
git_push() {
@@ -117,7 +117,7 @@ update_dependency() {
117117
# allow not to commit if there are no changes
118118
# previous execution could fail and just pushed the branch but PR is not created
119119
if ! git diff-index --quiet HEAD ; then
120-
git commit -m "Test elastic-package from PR ${BUILDKITE_PULL_REQUEST} - ${GITHUB_PR_HEAD_SHA}"
120+
git commit -m "Test package-spec from PR ${BUILDKITE_PULL_REQUEST} - ${GITHUB_PR_HEAD_SHA}"
121121
fi
122122

123123
echo ""

0 commit comments

Comments
 (0)