github.com/verrazzano/verrazzano@v1.7.1/ci/scripts/derive_oke_cluster_name.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2021, Oracle and/or its affiliates.
     4  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     5  #
     6  set -o pipefail
     7  
     8  if [ -z "$BRANCH_NAME" ] || [ -z "$SHORT_TIME_STAMP" ] || [ -z "$BUILD_NUMBER" ] ; then
     9    echo "This script must only be called from Jenkins and requires environment variables BRANCH_NAME, SHORT_TIME_STAMP and BUILD_NUMBER are set."
    10    exit 1
    11  fi
    12  
    13  # The prefix for the OKE cluster is derived using the BRANCH_NAME, SHORT_TIME_STAMP and BUILD_NUMBER as below
    14  # <8 or less alpha numeric characters from the branch><digit build number>-<10 digit timestamp>. The script truncates the
    15  # branch name and the timestamp, if they contain more than the expected characters.
    16  
    17  # Retain only alphanumeric characters from the BRANCH_NAME and truncate
    18  NEW_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9]//g')
    19  NEW_BRANCH=${NEW_BRANCH:0:8}
    20  
    21  CLUSTER_PREFIX="$NEW_BRANCH$BUILD_NUMBER"
    22  if (( ${#CLUSTER_PREFIX} > 13 )); then
    23    CLUSTER_PREFIX=${CLUSTER_PREFIX:0:13}
    24  fi
    25  
    26  TIMESTAMP=${SHORT_TIME_STAMP}
    27  if (( ${#TIMESTAMP} > 10 )); then
    28    TIMESTAMP=${TIMESTAMP:0:10}
    29  fi
    30  
    31  CLUSTER_PREFIX="$CLUSTER_PREFIX-$TIMESTAMP"
    32  echo "$CLUSTER_PREFIX"