Skip to content

Commit 8597e7d

Browse files
authored
Update branch name label for terraform (#1698)
1 parent d3e6191 commit 8597e7d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

.buildkite/hooks/pre-command

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,27 @@ export ENVIRONMENT="ci"
1616
REPO=$(repo_name "${BUILDKITE_REPO}")
1717
export REPO
1818

19-
# From Jenkins
20-
# BRANCH_NAME_LOWER_CASE = "${env.BRANCH_NAME.toLowerCase().replaceAll('[^a-z0-9-]', '-')}"
21-
BRANCH_NAME_LOWER_CASE=$(echo "$BUILDKITE_BRANCH" | tr '[:upper:]' '[:lower:]' | tr '_/\:. ' '-')
19+
branch_name_label() {
20+
local branch="$1"
21+
22+
if [[ "${BUILDKITE_PULL_REQUEST}" != "false" ]] ; then
23+
# remove fork from branch name
24+
branch=$(echo $branch | cut -d : -f 2)
25+
fi
26+
27+
# From Jenkins
28+
# BRANCH_NAME_LOWER_CASE = "${env.BRANCH_NAME.toLowerCase().replaceAll('[^a-z0-9-]', '-')}"
29+
# to lower case and replace characters
30+
branch=$(echo "$branch" | tr '[:upper:]' '[:lower:]' | tr '_/\:. ' '-')
31+
32+
# truncate up to 63 characters limit
33+
echo $branch | head -c 63
34+
}
35+
36+
BRANCH_NAME_LOWER_CASE=$(branch_name_label "$BUILDKITE_BRANCH")
2237
export BRANCH_NAME_LOWER_CASE
23-
export BUILD_ID="${BUILDKITE_BUILD_ID}"
38+
# This variable contains the build number https://buildkite.com/elastic/elastic-package/<number>
39+
export BUILD_ID="${BUILDKITE_BUILD_NUMBER}"
2440
# get current timestamp in milliseconds
2541
# From Jenkins
2642
# CREATED_DATE = "${new Date().getTime()}"

0 commit comments

Comments
 (0)