From 0e2cac632357d80210c7d0d8f9939835aee7d34a Mon Sep 17 00:00:00 2001 From: Barry Matheney Date: Thu, 20 Jun 2024 14:39:48 -0400 Subject: [PATCH] 20240620_143948 --- bitbucket-piplines.yml | 37 +++++++++++++++++++++++++++++++++ scr_non_secret_env_vars.sh | 5 +++++ scr_scrub_bitbucket_env_vars.sh | 32 ++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 bitbucket-piplines.yml create mode 100644 scr_non_secret_env_vars.sh create mode 100644 scr_scrub_bitbucket_env_vars.sh diff --git a/bitbucket-piplines.yml b/bitbucket-piplines.yml new file mode 100644 index 000000000..13992d9c5 --- /dev/null +++ b/bitbucket-piplines.yml @@ -0,0 +1,37 @@ +image: atlassian/default-image:4 + +pipelines: + branches: + master: # Trigger this for any pushes to the master branch. + - step: + name: Buildpack + trigger: automatic + # caches: + # - maven # Cache any dependencies we download, speeds up build times. + services: + - docker + caches: + - docker + script: + - ps -p $$ && echo whoami && printenv | sort && cat /etc/os-release + - echo "$SHELL" + - source scr_scrub_bitbucket_env_vars.sh + - source scr_non_secret_env_vars.sh + - docker build + # - source pack_install.sh + # - which pack && pack version + # - bash create-settings.sh # Create our settings.xml file. Will fail if environment variables aren't set properly. + # - mvn -B -s settings.xml verify # Ensure all artifacts build successfully before we attempt deploy in order to prevent partial deploys. + # - mvn -B -s settings.xml deploy # Now that all builds have completed, we can deploy all the artifacts. + # - step: + # name: Create Release Version # This will create a release version and commit it to master. It will then be picked up and deployed in the first step. + # trigger: manual + # caches: + # - maven + # script: + # - bash create-settings.sh # Create our settings.xml file. Will fail if environment variables aren't set properly. + # - bash validate-release-configuration.sh # Do the best we can to ensure we have the SSH keys and env variables in place before we try to prepare a release. + # - git config --global user.email "$GIT_USER_EMAIL" + # - git config --global user.name "$GIT_USER_NAME" + # - mvn -B -s settings.xml -DdryRun=true release:prepare # Ensure that most things will run properly before we do the real work. + # - mvn -B -s settings.xml release:clean release:prepare # This bumps the versions in the poms, creates new commits, which will then get built by the master branch trigger. diff --git a/scr_non_secret_env_vars.sh b/scr_non_secret_env_vars.sh new file mode 100644 index 000000000..2e4c973ab --- /dev/null +++ b/scr_non_secret_env_vars.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +echo "$(date +%Y%m%d_%H%M%S) - Entering $(basename "$(realpath "${BASH_SOURCE[0]}")") on host $(hostname)" + +echo "$(date +%Y%m%d_%H%M%S) - Leaving $(basename "$(realpath "${BASH_SOURCE[0]}")") on host $(hostname)" + diff --git a/scr_scrub_bitbucket_env_vars.sh b/scr_scrub_bitbucket_env_vars.sh new file mode 100644 index 000000000..9bbdd2dd2 --- /dev/null +++ b/scr_scrub_bitbucket_env_vars.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# List of characters to replace +declare -A char_replacements=( + [" "]=_ + ["/"]=_ + [":"]=_ + ["("]=_ + [")"]=_ + ["{"]=_ + ["}"]=_ + ["-"]=_ +) + +# Function to scrub a string +scrub_string() { + local string=$1 + for char in "${!char_replacements[@]}"; do + string=${string//"$char"/"${char_replacements[$char]}"} + done + echo "$string" +} + +# Iterate through environment variables +for var in $(printenv | grep '^BITBUCKET_' | cut -d= -f1); do + # Get the value of the variable + value=$(printenv "$var") + # Scrub the value + scrubbed_value=$(scrub_string "$value") + # Create a new variable with the scrubbed value + export "${var}_SCRUBBED=$scrubbed_value" + echo "${var}_SCRUBBED=$scrubbed_value" +done