gitlab-ci運行參數

# 最早執行語句
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
相關文章
相關標籤/搜索