diff --git a/Jenkinsfile b/Jenkinsfile index e8bf12d..a846962 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,11 +31,7 @@ def wrap = { fn-> variable: 'GOOGLE_APPLICATION_CREDENTIALS_OVERRIDE')]) { withCredentials([string(credentialsId: 'newrelic.license.key', variable: 'NEWRELIC_LICENSE_KEY_OVERRIDE')]) { - sh (""" - cp env.sh.sample env.sh - rm -rf build - mkdir build - """) + sh ("bin/clean-workspace.sh") fn() } } diff --git a/bin/clean-workspace.sh b/bin/clean-workspace.sh new file mode 100755 index 0000000..a227196 --- /dev/null +++ b/bin/clean-workspace.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# clean workspace +# +# Set bash unofficial strict mode http://redsymbol.net/articles/unofficial-bash-strict-mode/ +set -euo pipefail + +# Set DEBUG to true for enhanced debugging: run prefixed with "DEBUG=true" +${DEBUG:-false} && set -vx +# Credit to https://stackoverflow.com/a/17805088 +# and http://wiki.bash-hackers.org/scripting/debuggingtips +export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' + +# Credit to http://stackoverflow.com/a/246128/424301 +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BASE_DIR="$DIR/.." +BUILD_DIR="$BASE_DIR/build" +export BASE_DIR + +# shellcheck disable=SC1090 +. "$DIR/common.sh" + +cp "$BASE_DIR/env.sh.sample" "$BASE_DIR/env.sh" +clean_root_owned_docker_files +rm -rf "$BUILD_DIR" +mkdir "$BUILD_DIR" diff --git a/bin/codedeploy/AfterInstall.sh b/bin/codedeploy/AfterInstall.sh index 93d1db5..2fcbca4 100755 --- a/bin/codedeploy/AfterInstall.sh +++ b/bin/codedeploy/AfterInstall.sh @@ -16,7 +16,7 @@ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' # Credit to http://stackoverflow.com/a/246128/424301 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -BASE_DIR="$DIR/.." +BASE_DIR="$DIR/../.." ANSIBLE_DIR="$BASE_DIR/ansible" # Invoke Ansible for final set up diff --git a/bin/codedeploy/ApplicationStart.sh b/bin/codedeploy/ApplicationStart.sh index 5d08139..c2698ca 100755 --- a/bin/codedeploy/ApplicationStart.sh +++ b/bin/codedeploy/ApplicationStart.sh @@ -16,7 +16,7 @@ export PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }' # Credit to http://stackoverflow.com/a/246128/424301 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -BASE_DIR="$DIR/.." +BASE_DIR="$DIR/../.." ANSIBLE_DIR="$BASE_DIR/ansible" # Invoke Ansible for final set up