在
build
作业和
pages
作业之前,执行
npm install
命令(每个作业之前一次)。由于我有很多包裹,所以这通常需要一段时间。
有一种方法只能在整个构建中进行一次安装?
我以为这是应该有所帮助的,但似乎仍然可以减少所有内容。
评论中的答案基本上是正确的。我认为您案件的具体答案会很好。您可以使用的一种方法是添加第三阶段,该阶段将承受安装节点模块的负载,而且您还可以缓存它们以加快后续构建:
cache
该解决方案只能执行一次安装,并将用于将来的CI管道的结果,您也可以在节点模块伪像。
您需要设置
image: node:latest
stages:
- prep
- build
- deploy
before_script:
- npm install gulp-cli -g
prep:
stage: prep
script:
- npm install gulp [...and a whole bunch of packages] --save-dev
artifacts:
paths:
- node_modules
cache:
paths:
- node_modules
build:
stage: build
script:
- gulp buildsite
artifacts:
paths:
- public
pages:
stage: deploy
script:
- gulp
artifacts:
paths:
- public
cache:
untracked: true
有两种做到这一点的方法;使用
cache:
untracked: true
paths:
- node_modules/
并使用cache
。您可以阅读有关差异的文章,但本质上是:
如果您的工作确实依赖上一个的输出(即无法单独产生),则使用工件和依赖项。
如果您在选择缓存或工件之间挣扎,那么请记住一个简单的句子:
→缓存在这里加快您的工作,但可能不存在,所以不要依靠它。在这种情况下,如果您不需要在管道完成后访问
artifacts
文件夹,请使用Cachenode_modules
cache:
untracked: true
paths:
- node_modules/
Artifacts
。将其添加到构建步骤中:
node_modules
将其添加到需要node_modules
目录的以下步骤中:artifacts:
paths:
- node_modules