gitlab-ci运行参数

原创
2018/12/06 18:27
阅读数 807
# 最先执行语句
before_script:
  - APP_NAME=microservice-staff
  - echo APP_NAME = $APP_NAME , CI_BUILD_REF_NAME = $CI_BUILD_REF_NAME
  - IPORT=8082
  - if [ $CI_BUILD_REF_NAME == dev ]; then PORT=8082; else PORT=9082; fi;

# 定义stage,build(构建)、test(测试)、deploy(部署)
stages:
  - build
  - test
  - deploy

# build: build image
job_build:
  stage: build
  script:
  - docker build -t registry-vpc.cn-beijing.aliyuncs.com/ysn/$APP_NAME:$CI_BUILD_REF_NAME .
  only:
    - dev
    - test
    - master
  tags:
    - shared_runner_shell

# test: dev/test环境
job_test:
  stage: test
  script:
  - if [ `docker ps -aq -f name=$APP_NAME-$CI_BUILD_REF_NAME` ]; 
    then 
	# 优雅停服
	curl --request POST http://localhost:$PORT/shutdown;
    docker stop $APP_NAME-$CI_BUILD_REF_NAME; 
    docker rm $APP_NAME-$CI_BUILD_REF_NAME; 
    fi
  - docker run
    --name $APP_NAME-$CI_BUILD_REF_NAME
    -d -p $PORT:$IPORT
    --network s-net --network-alias $APP_NAME-$CI_BUILD_REF_NAME
    -w /usr/src/myapp
    -v ahas-javaagent:/var/lib/aliyunahas/agent:rw
    -e JAVA_OPTS="-Xms128m -Xmx128m -Xmn128m -Xss1024k 
       -Dspring.profiles.active=${CI_BUILD_REF_NAME} 
       -Dproject.name=${APP_NAME}-${CI_BUILD_REF_NAME} 
       -javaagent:/var/lib/aliyunahas/agent/ahas-java-agent.jar"
    --restart=on-failure
    registry-vpc.cn-beijing.aliyuncs.com/ysn/$APP_NAME:$CI_BUILD_REF_NAME
  only:
    - dev
    - test
  tags:
    - shared_runner_shell

# deploy:推送阿里云容器服务部署
job_deploy:
  stage: deploy
  script:
  - sudo docker push registry-vpc.cn-beijing.aliyuncs.com/ysn/$APP_NAME:$CI_BUILD_REF_NAME
  only:
    - master
  tags:
    - shared_runner_shell
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部