stage('设定配置文件'){ steps{ sh ''' . ~/.bash_profile if [[ "${env}" == "prod" ]]; then export mysql_ip=${mysql_prod_ip} export mysql_port=${mysql_prod_port} else export mysql_ip=${mysql_qa_ip} export mysql_port=${mysql_qa_port} fi export os_type=`uname` cd ${WORKSPACE}/web/bin/docker if [[ "${os_type}" == "Darwin" ]]; then sed -i "" "s/mysql_ip/${mysql_ip}/g" application-${env}.yml sed -i "" "s/mysql_port/${mysql_port}/g" application-${env}.yml sed -i "" "s/mysql_user/${mysql_user}/g" application-${env}.yml sed -i "" "s/mysql_pwd/${mysql_pwd}/g" application-${env}.yml sed -i "" "s/<env>/${env}/g" Dockerfile-param else sed -i "s/mysql_ip/${mysql_ip}/g" application-${env}.yml sed -i "s/mysql_port/${mysql_port}/g" application-${env}.yml sed -i "s/mysql_user/${mysql_user}/g" application-${env}.yml sed -i "s/mysql_pwd/${mysql_pwd}/g" application-${env}.yml sed -i "s/<env>/${env}/g" Dockerfile-param fi ''' } }
stage('Maven 编译'){ steps { sh ''' . ~/.bash_profile cd ${WORKSPACE}/root mvn clean install -Dmaven.test.skip=true cd ${WORKSPACE}/web mvn clean package spring-boot:repackage -Dmaven.test.skip=true -U ''' } }
stage('停止 / 删除 现有Docker Container/Image '){ steps { script{ try{ sh 'docker stop ${docker_container}-${env}' }catch(exc){ echo "The container ${docker_container}-${env} does not exist" }
try{ sh 'docker rm ${docker_container}-${env}' }catch(exc){ echo "The container ${docker_container}-${env} does not exist" }
try{ sh 'docker rmi ${docker_image}-${env}' }catch(exc){ echo "The docker image ${docker_image}-${env} does not exist" } } } }