-
Notifications
You must be signed in to change notification settings - Fork 16
/
push-image-to-nexus.sh
40 lines (38 loc) · 2.36 KB
/
push-image-to-nexus.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
if [ ${TRAVIS_PULL_REQUEST} != "false" ]; then echo "Not publishing a pull request !!!" && exit 0; fi
export BRANCH_NAME=`echo "${TRAVIS_BRANCH}" | tr '[:upper:]' '[:lower:]'`
case "${BRANCH_NAME}" in
dev*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
ao-dev*)echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
qa*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
qe*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
rc*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
release-master*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI/CD" ;;
ft*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI" ;;
bf*) echo "Branch ${TRAVIS_BRANCH} is eligible for CI" ;;
*) echo "Not a valid branch name for CI/CD" && exit -1;;
esac
echo $TRAVIS_BRANCH
echo ${DEPLOYMENT_SERVER}
export SHORT_COMMIT=`git rev-parse --short=7 ${TRAVIS_COMMIT}`
echo "short commit $SHORT_COMMIT"
sudo apt-get update
sudo apt-get install -y jq
IMAGE_NAME=`echo "${BUILD_REPO_NAME}_${TRAVIS_BRANCH}" | tr '[:upper:]' '[:lower:]'`
PACKAGE_NAME=`jq '.name' version.json | tr -d '"'`
PACKAGE_VERSION=`jq '.version' version.json | tr -d '"'`
echo "Package name : ${PACKAGE_NAME}"
PHP_SDK_NAME=`jq '.php_sdk_name' version.json | tr -d '"'`
PHP_BRANCH_NAME=`jq '.php_sdk_branch' version.json | tr -d '"'`
PHP_SDK_GIT_URL=`jq '.php_sdk_repo' version.json | tr -d '"'`
echo "SDK: ${PHP_SDK_NAME} , branch: ${PHP_BRANCH_NAME} , version: ${PACKAGE_VERSION} , git url: ${PHP_SDK_GIT_URL}"
echo "IP address of BUILD agent is: " && hostname -I
echo "Hostname of BUILD agent is: " && hostname
docker image prune -f
docker build -t ${IMAGE_NAME}:${SHORT_COMMIT} --build-arg PackageName=${PACKAGE_NAME} --build-arg PackageVersion=${PACKAGE_VERSION} --build-arg NexusUser=${NEXUS_USER} --build-arg NexusPassword=${NEXUS_USER_PWD} --build-arg GitUsr=${GITHUB_USR} --build-arg GitToken=${GITHUB_TOKEN} --build-arg PHPsdkGitURL=${PHP_SDK_GIT_URL} --build-arg PHPsdkBranch=${PHP_BRANCH_NAME} .
sleep 3
docker image ls
echo "uploading to nexus ${NEXUS_CR_TOOLS_URL}/froala-${IMAGE_NAME}:${PACKAGE_VERSION} "
docker login -u ${NEXUS_USER} -p ${NEXUS_USER_PWD} ${NEXUS_CR_TOOLS_URL}
docker tag ${IMAGE_NAME}:${SHORT_COMMIT} ${NEXUS_CR_TOOLS_URL}/froala-${IMAGE_NAME}:${PACKAGE_VERSION}
docker push ${NEXUS_CR_TOOLS_URL}/froala-${IMAGE_NAME}:${PACKAGE_VERSION}