Last active
May 19, 2019 11:12
-
-
Save parj/d283372c00ebc222ea07488f5a88388e to your computer and use it in GitHub Desktop.
Multi CI - Travis CI and Circle CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Stop on error | |
set -e | |
main() { | |
init | |
setup_git | |
buildArtifact | |
} | |
init() { | |
exeinf "Starting..." | |
} | |
# From gist - https://gist.github.com/Bost/54291d824149f0c4157b40329fceb02c | |
tstp() { | |
date +"%Y-%m-%d %H:%M:%S,%3N" | |
} | |
# From gist - https://gist.github.com/Bost/54291d824149f0c4157b40329fceb02c | |
exeinf() { | |
echo "INFO " $(tstp) "$ "$@ | |
} | |
# From gist - https://gist.github.com/Bost/54291d824149f0c4157b40329fceb02c | |
exeerr() { | |
echo "ERROR" $(tstp) "$ "$@ | |
} | |
setup_git() { | |
exeinf "Setting up git" | |
git config --global user.email "[email protected]" | |
git config --global user.name "Travis CI" | |
} | |
pushTagsAndCommit() { | |
exeinf "Pushing tags" | |
git push --tags | |
exeinf "Pushing maven commit" | |
git push -u origin release | |
} | |
#Required as mvn:release bumps tags | |
buildDockerImageFromLatestTag() { | |
latesttag=$(git describe --tags) | |
exeinf "Checking out latest tags ${latesttag}" | |
git checkout ${latesttag} | |
mvn package docker:build -DskipTests | |
} | |
buildArtifact() { | |
if [[ $TRAVIS_BRANCH == "release" ]] || [[ $CIRCLE_BRANCH = "release" ]]; then | |
exeinf "Release build" | |
if [[ ! -z $TRAVIS_BRANCH ]]; then | |
export TRAVIS_TAG="TRAVIS.$TRAVIS_BUILD_NUMBER" | |
git tag "$TRAVIS_TAG" "$TRAVIS_COMMIT" | |
elif [[ ! -z $CIRCLE_BRANCH ]]; then | |
export CIRCLECI_TAG="CIRCLE.$CIRCLE_BUILD_NUM" | |
git tag "$CIRCLECI_TAG" | |
fi | |
#Just do a dry run on TravisCI | |
if [[ $TRAVIS_BRANCH == "release" ]]; then | |
mvn -B -s .travis/settings.xml release:clean release:prepare -DdryRun=true | |
fi | |
#Only perform full release on circleci | |
if [[ $CIRCLE_BRANCH = "release" ]] && [[ -z $CIRCLE_TAG ]]; then | |
exeinf "Performing maven release" | |
mvn -B -s .travis/settings.xml release:clean release:prepare release:perform -DscmCommentPrefix="[skip ci] [maven-release-plugin] " | |
pushTagsAndCommit | |
buildDockerImageFromLatestTag | |
fi | |
else | |
exeinf "Snapshot build" | |
mvn -s .travis/settings.xml deploy docker:build | |
fi | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment