我正在使用gitlab CI / CD在Firebase上部署我的角度应用程序。
我有两个阶段:build
和deploy
。
image: node:11.2.0
stages:
- build
- deploy
cache:
paths:
- node_modules/
build:
stage: build
script:
- npm i
- npm i -g @angular/cli@7.3.1
- ng build --prod
only:
- master
- dev
- merge_requests
deploy_prod:
stage: deploy
script:
- npm i
- npm i -g @angular/cli@7.3.1
- ng build --prod
- npm i -g firebase-tools
- firebase use --token "$FIREBASE_TOKEN" project-name
- firebase deploy --token "$FIREBASE_TOKEN" --non-interactive
environment:
name: prod
only:
- master
如您所见,在部署阶段,我太重复了:
- npm i
- npm i -g @angular/cli@7.3.1
- ng build --prod
是否可以使用已完成的操作来使CI / CD更快?
正确的做法是什么?
答案 0 :(得分:2)
可以有多种方法。您可以将它们移至外部脚本并进行调用,否则最好的方法是使用anchors。示例:
.job_template: &job_definition # Hidden key that defines an anchor named 'job_definition'
image: ruby:2.1
services:
- postgres
- redis
test1:
<<: *job_definition # Merge the contents of the 'job_definition' alias
script:
- test1 project
test2:
<<: *job_definition # Merge the contents of the 'job_definition' alias
script:
- test2 project
答案 1 :(得分:0)
感谢Arty-chan,该解决方案是关于Artifacts的:https://docs.gitlab.com/ee/ci/caching/#cache-vs-artifacts
image: node:11.2.0
stages:
- build
- deploy
cache:
paths:
- node_modules/
.job_template: &job_definition
script:
- npm i
- npm i -g @angular/cli@7.3.1
- ng build --prod
build:
stage: build
<<: *job_definition
artifacts:
paths:
- dist/
only:
- master
- dev
- merge_requests
deploy_prod:
stage: deploy
<<: *job_definition
script:
- npm i -g firebase-tools
- firebase use --token "$FIREBASE_TOKEN" project-name
- firebase deploy --token "$FIREBASE_TOKEN" --non-interactive
environment:
name: prod
only:
- master