最近在搞jenkins + docker CI,把自己写的集成脚本分享出来给大家。里面很多路径或者名称是我自己的,自行替换掉。
#!/bin/sh# Jenkins Build Shell Script# Author zdzhou@set -e # Get running docker image namecid=`docker ps | grep 'isearch' | awk {'print $1'}`echo $cid# If exists running isearch docker image, stop and remove itif [ -n "$cid" ]thenecho Get the running docker container id of isearch: $ciddocker stop $ciddocker rm $cidelse echo There is no running isearch docker containerfi# Copy target war to dest directorycd ${JENKINS_HOME}/workspace/${JOB_NAME}/itv-web/echo Current work directory `pwd`cp target/itv-web.war /usr/local/tomcat/webappsecho Run docker imagedocker run -d -p 8080:8080 -v /usr/local/isearch:/usr/local/isearch -v /usr/local/tomcat/webapps:/usr/local/tomcat/webapps --name=isearch${SVN_REVISION} isearch# Wait for starting docker containertotalWait=0until [ "`/usr/bin/docker inspect -f {{.State.Running}} isearch${SVN_REVISION}`" == "true" ] dototalWait=$[ $totalWait + 2 ]if (( $totalWait > 10 ))thenecho "Start docker container timeout"exit 1fiecho "Waiting for starting docker container: $totalWait minute" sleep 2mdoneecho "Start docker container success "# Wait for starting tomcattotalWait=0until [ "`curl -o /dev/null --silent -m 10 --retry 1 --connect-timeout 10 --head --write-out '%{http_code}\n' http://127.0.0.1:8080/itv-web/v3/videosearch/?appid=aginomoto`" = "200" ]do totalWait=$[ $totalWait + 3 ]if (($totalWait > 36 ))then echo "Start tomcat timeout"exit 1fiecho "Wait for starting tomcat: "$totalWait" minute"sleep 3mdone echo "Start tomcat service success"# Run automatic function test scriptecho "Start automatic function test"export LOG_HOME=${WORKSPACE}/test.log.d/${BUILD_NUMBER}cd /data/jenkins_home/test.framework.dexec ./automatic_test.sh
原文链接/a/1190000004297705