Skip to content

Commit c4a2495

Browse files
authored
Ensure job name is a valid k8s resource name (#23)
* Ensure job name is a valid k8s resource name Fixes #17 * allow numeric at start and end
1 parent bd36566 commit c4a2495

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

hooks/command

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ set -euo pipefail
44

55
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
66

7-
job_name="${BUILDKITE_PIPELINE_SLUG}-${BUILDKITE_BUILD_NUMBER}-$(head -c 5 /dev/urandom | base32 | tr '[:upper:]' '[:lower:]')"
7+
# Ensure a name is a valid k8s resource name.
8+
function sanitize() {
9+
echo "$@" | sed -E 's/[^A-Za-z0-9]/-/g' | sed -E 's/^[^a-zA-Z0-9]|[^a-zA-Z0-9]$//' | cut -c 1-63
10+
}
11+
12+
job_name=$(sanitize "${BUILDKITE_PIPELINE_SLUG}-${BUILDKITE_BUILD_NUMBER}-$(head -c 5 /dev/urandom | base32 | tr '[:upper:]' '[:lower:]')")
813
echo "${job_name}" > /tmp/job_name
914

1015
if [[ ${BUILDKITE_TIMEOUT:-"false"} == "false" ]]; then

0 commit comments

Comments
 (0)