├── README.md ├── deploytoqa └── deploytodev /README.md: -------------------------------------------------------------------------------- 1 | # jenkinsose3 2 | Scripts to deploy a JBossEAP app to OSE3 from Jenkins 3 | 4 | This project has scripts to deploy to development and to deploy to QA. 5 | 6 | -------------------------------------------------------------------------------- /deploytoqa: -------------------------------------------------------------------------------- 1 | oc project $DEVEL_PROJ_NAME 2 | 3 | IS_NAME=`oc get is| tail -1|awk '{print $1}'` 4 | 5 | #get full name of the image 6 | FULL_IMAGE_NAME=`oc describe is ${IS_NAME} | grep -a1 "Tag" | tail -1 | awk '{print $6}'` 7 | 8 | #Tag to promote to QA 9 | oc tag $FULL_IMAGE_NAME $DEVEL_PROJ_NAME/${IS_NAME}:promote 10 | 11 | 12 | #This should automatically initiate deployment 13 | 14 | oc project $QA_PROJ_NAME 15 | 16 | #Find the DeploymentConfig to see if this is a new deployment or just needs an update 17 | DC_ID=`oc get dc | tail -1| awk '{print $1}'` 18 | 19 | if [ $DC_ID == "NAME" ]; then 20 | oc new-app $DEVEL_PROJ_NAME/${IS_NAME}:promote --name=$APP_NAME 21 | SVC_ID=`oc get svc | tail -1 | awk '{print $1}'` 22 | oc expose service $SVC_ID --hostname=$APP_HOSTNAME 23 | fi 24 | 25 | 26 | #find the new rc based on the FULL_IMAGE_NAME=$FULL_IMAGE_NAME 27 | RC_ID="" 28 | attempts=75 29 | count=0 30 | while [ -z "$RC_ID" -a $count -lt $attempts ]; do 31 | RC_ID=`oc get rc | grep $FULL_IMAGE_NAME | awk '{print $1}'` 32 | count=$(($count+1)) 33 | sleep 5 34 | done 35 | 36 | if [ -z "$RC_ID" ]; then 37 | echo "Fail: App deployment was not successful" 38 | exit 1 39 | fi 40 | 41 | #Scale the app to 1 pod (just to make sure) 42 | scale_result=`oc scale rc $RC_ID --replicas=1| awk '{print $3}'` 43 | 44 | if [ $scale_result != "scaled" ]; then 45 | echo "Fail: Scaling not successful" 46 | exit 1 47 | fi 48 | -------------------------------------------------------------------------------- /deploytodev: -------------------------------------------------------------------------------- 1 | oc login -u$USER_NAME -p$USER_PASSWD --server=$OSE_SERVER --certificate-authority=$CERT_PATH 2 | 3 | oc project $DEVEL_PROJ_NAME 4 | 5 | #Is this a new deployment or an existing app? Decide based on whether the project is empty or not 6 | #If BuildConfig exists, assume that the app is already deployed and we need a rebuild 7 | 8 | BUILD_CONFIG=`oc get bc | tail -1 | awk '{print $1}'` 9 | 10 | if [ -z "$BUILD_CONFIG" -o $BUILD_CONFIG == "NAME" ]; then 11 | 12 | # no app found so create a new one 13 | echo "Create a new app" 14 | oc new-app --template=eap6-basic-sti -p \ 15 | APPLICATION_NAME=$APP_NAME,APPLICATION_HOSTNAME=$APP_HOSTNAME,EAP_RELEASE=6.4,GIT_URI=$APP_GIT,GIT_REF=$APP_GIT_REF,GIT_CONTEXT_DIR=$APP_GIT_CONTEXT_DIR\ 16 | -l name=$APP_NAME 17 | 18 | echo "Find build id" 19 | BUILD_ID=`oc get builds | tail -1 | awk '{print $1}'` 20 | rc=1 21 | attempts=75 22 | count=0 23 | while [ $rc -ne 0 -a $count -lt $attempts ]; do 24 | BUILD_ID=`oc get builds | tail -1 | awk '{print $1}'` 25 | if [ $BUILD_ID == "NAME" ]; then 26 | count=$(($count+1)) 27 | echo "Attempt $count/$attempts" 28 | sleep 5 29 | else 30 | rc=0 31 | echo "Build Id is :" ${BUILD_ID} 32 | fi 33 | done 34 | 35 | if [ $rc -ne 0 ]; then 36 | echo "Fail: Build could not be found after maximum attempts" 37 | exit 1 38 | fi 39 | else 40 | 41 | # Application already exists, just need to start a new build 42 | echo "App Exists. Triggering application build and deployment" 43 | BUILD_ID=`oc start-build ${BUILD_CONFIG}` 44 | 45 | fi 46 | 47 | echo "Waiting for build to start" 48 | rc=1 49 | attempts=25 50 | count=0 51 | while [ $rc -ne 0 -a $count -lt $attempts ]; do 52 | status=`oc get build ${BUILD_ID} -t '{{.status.phase}}'` 53 | if [[ $status == "Failed" || $status == "Error" || $status == "Canceled" ]]; then 54 | echo "Fail: Build completed with unsuccessful status: ${status}" 55 | exit 1 56 | fi 57 | if [ $status == "Complete" ]; then 58 | echo "Build completed successfully, will test deployment next" 59 | rc=0 60 | fi 61 | 62 | if [ $status == "Running" ]; then 63 | echo "Build started" 64 | rc=0 65 | fi 66 | 67 | if [ $status == "Pending" ]; then 68 | count=$(($count+1)) 69 | echo "Attempt $count/$attempts" 70 | sleep 5 71 | fi 72 | done 73 | 74 | # stream the logs for the build that just started 75 | oc build-logs $BUILD_ID 76 | 77 | 78 | 79 | echo "Checking build result status" 80 | rc=1 81 | count=0 82 | attempts=100 83 | while [ $rc -ne 0 -a $count -lt $attempts ]; do 84 | status=`oc get build ${BUILD_ID} -t '{{.status.phase}}'` 85 | if [[ $status == "Failed" || $status == "Error" || $status == "Canceled" ]]; then 86 | echo "Fail: Build completed with unsuccessful status: ${status}" 87 | exit 1 88 | fi 89 | 90 | if [ $status == "Complete" ]; then 91 | echo "Build completed successfully, will test deployment next" 92 | rc=0 93 | else 94 | count=$(($count+1)) 95 | echo "Attempt $count/$attempts" 96 | sleep 5 97 | fi 98 | done 99 | 100 | if [ $rc -ne 0 ]; then 101 | echo "Fail: Build did not complete in a reasonable period of time" 102 | exit 1 103 | fi 104 | 105 | 106 | echo "Checking build result status" 107 | rc=1 108 | count=0 109 | attempts=100 110 | while [ $rc -ne 0 -a $count -lt $attempts ]; do 111 | status=`oc get build ${BUILD_ID} -t '{{.status.phase}}'` 112 | if [[ $status == "Failed" || $status == "Error" || $status == "Canceled" ]]; then 113 | echo "Fail: Build completed with unsuccessful status: ${status}" 114 | exit 1 115 | fi 116 | 117 | if [ $status == "Complete" ]; then 118 | echo "Build completed successfully, will test deployment next" 119 | rc=0 120 | else 121 | count=$(($count+1)) 122 | echo "Attempt $count/$attempts" 123 | sleep 5 124 | fi 125 | done 126 | 127 | if [ $rc -ne 0 ]; then 128 | echo "Fail: Build did not complete in a reasonable period of time" 129 | exit 1 130 | fi 131 | 132 | # scale up the test deployment 133 | RC_ID=`oc get rc | tail -1 | awk '{print $1}'` 134 | 135 | echo "Scaling up new deployment $test_rc_id" 136 | oc scale --replicas=1 rc $RC_ID 137 | 138 | 139 | echo "Checking for successful test deployment at $HOSTNAME" 140 | set +e 141 | rc=1 142 | count=0 143 | attempts=100 144 | while [ $rc -ne 0 -a $count -lt $attempts ]; do 145 | if curl -s --connect-timeout 2 $APP_HOSTNAME >& /dev/null; then 146 | rc=0 147 | break 148 | fi 149 | count=$(($count+1)) 150 | echo "Attempt $count/$attempts" 151 | sleep 5 152 | done 153 | set -e 154 | 155 | if [ $rc -ne 0 ]; then 156 | echo "Failed to access test deployment, aborting roll out." 157 | exit 1 158 | fi 159 | 160 | 161 | ################################################################################ 162 | ##Include development test scripts here and fail with exit 1 if the tests fail## 163 | ################################################################################ 164 | --------------------------------------------------------------------------------