gitlab-ci运行参数

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

# 最先执行语句
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

转载于:https://my.oschina.net/u/3656540/blog/2980527

你可能感兴趣的:(gitlab-ci运行参数)