gitlab自动编译实现按分支编译

376 阅读1分钟
stages:
  - build
  - package
  - deploy-dev
  - deploy-prd

variables:
  SERVICE_NAME: jbs-quesformtable # 服务名


build-dev:
  image: $REGISTRY_ADDRESS/devops/nodejs/build
  stage: build
  only:
    - develop
  script: # 编译命令
    - yarn config get registry && yarn config set registry "https://registry.npmmirror.com" && yarn && yarn build:test
  artifacts:
    paths:
      - dist
      - Dockerfile
    expire_in: 2 hrs
  tags:
    - nodejs

build-prd:
  image: $REGISTRY_ADDRESS/devops/nodejs/build
  stage: build
  only:
    - master
  script:
    - yarn config get registry && yarn config set registry "https://registry.npmmirror.com" && yarn && yarn build:pro
  artifacts:
    paths:
      - dist
      - Dockerfile
    expire_in: 2 hrs
  tags:
    - nodejs

package:
  image: $REGISTRY_ADDRESS/devops/docker/package
  stage: package
  variables:
    GIT_STRATEGY: none
  only:
    - master
    - develop
  script:
    - package
  tags:
    - docker

.deploy_job: &deploy_job
  image: $REGISTRY_ADDRESS/devops/docker/deploy
  variables:
    GIT_STRATEGY: none
  dependencies: []
  script: deploy -service $SERVICE_NAME -template web -vars host=yc.aiads-dev.com,port=80 # 指定访问域名和端口
  tags:
    - docker

deploy-dev:
  <<: *deploy_job
  only:
    - develop
  stage: deploy-dev
  environment: aiads-dev


deploy-prd:
  <<: *deploy_job
  only:
    - master
  stage: deploy-prd
  environment: aiads-prd
  retry: 2
  when: manual