Skip to content

Instantly share code, notes, and snippets.

@karimsa
Last active March 23, 2019 01:00
Show Gist options
  • Save karimsa/737c7220348bfa0a3d4e4689bcc34491 to your computer and use it in GitHub Desktop.
Save karimsa/737c7220348bfa0a3d4e4689bcc34491 to your computer and use it in GitHub Desktop.
CI-agnostic Env Variables
#!/bin/bash -e
## Maps env variables from different CIs to common names. Useful for changing between CIs.
##
## eval "$(curl -sSL https://gist.githubusercontent.com/karimsa/737c7220348bfa0a3d4e4689bcc34491/raw/ci-env.sh)"
##
## Licensed under MIT license.
## Copyright (C) 2019-present Karim Alibhai. All rights reserved.
if test "$CI" != "true"; then
echo "Not a CI."
exit 1
fi
###########################################
## $BRANCH - Current branch mapping ##
###########################################
export BRANCH="$BRANCH"
if ! test -z "$TRAVIS_BRANCH"; then ## Travis CI
export BRANCH="$TRAVIS_BRANCH";
elif ! test -z "$BRANCH_NAME"; then ## Semaphore CI
export BRANCH="$BRANCH_NAME";
elif which git &>/dev/null; then ## Anything else?
export BRANCH="$(git rev-parse --abbrev-ref HEAD)"
fi
#################################################
## $BUILD_ID - Unique identifier for the build ##
#################################################
export BUILD_ID="$BUILD_ID"
if ! test -z "$TRAVIS_BUILD_ID"; then
export BUILD_ID="$TRAVIS_BUILD_ID"
elif ! test -z "$SEMAPHORE_BUILD_NUMBER"; then
export BUILD_ID="$SEMAPHORE_BUILD_NUMBER"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment