Estou tentando automatizar um build utilizando o gitlab-ci.yml, porém estou tendo alguns problemas. Aparentemente cada stage cria um novo container da imagem que eu escolhi. Adianto que sou novo nesse mundo de CI/CD então talvez a maneira que eu esteja fazendo as coisas não seja a mais apropriada. Segue o script e o retorno obtido:
.gitlab-ci.yml
image: ubuntu:18.04
stages:
- prepare
- build
- deploy
Preparando ambiente:
stage: prepare
script:
- apt-get update -qq
- apt-get install -qq npm curl wget
- npm i -g n
- n latest
- apt-get autoclean -qq
only:
refs:
- dev
changes:
- "**/*.ts"
- "**/*.html"
- "**/*.css"
- "**/*.js"
Build Angular:
stage: build
script:
- cd view && npm run build
- echo "Build - OK"
only:
refs:
- dev
changes:
- "**/*.ts"
- "**/*.html"
- "**/*.css"
- "**/*.js"
Deploy:
stage: deploy
script:
- ls -la view/dist
only:
refs:
- dev
cache:
paths:
- view/dist
- view/node_modules
Ao comitar na dev quando passa do primeiro stage para o segundo ele não consegue fazer uso da dependência instalada anteriormente. Eu sei que posso colocar tudo no before_script porém ele vai ficar atualizando a distro e refazendo a instalação para todos os passos, mas fica muito lento.
Alguém poderia me ajudar em como proceder? Obrigado.
Retorno
Running with gitlab-runner 12.2.0 (a987417a)
on 781023241e32 EkxrYDXp
Using Docker executor with image ubuntu:18.04 ...
Pulling docker image ubuntu:18.04 ...
Using docker image sha256:a2a15febcdf362f6115e801d37b5e60d6faaeedcb9896155e5fe9d754025be12 for ubuntu:18.04 ...
Running on runner-EkxrYDXp-project-44-concurrent-0 via 781023241e32...
Fetching changes...
Reinitialized existing Git repository in /builds/teste/angular-teste/.git/
Checking out 37ff685b as dev...
Removing view/node_modules/.cache/terser-webpack-plugin/index-v5/0b/
Removing view/node_modules/.cache/terser-webpack-plugin/index-v5/21/
Removing view/node_modules/.cache/terser-webpack-plugin/index-v5/57/
Removing view/node_modules/.cache/terser-webpack-plugin/index-v5/88/b7/
Removing view/node_modules/.cache/terser-webpack-plugin/index-v5/a3/
Removing view/node_modules/.cache/terser-webpack-plugin/index-v5/ef/
Removing view/node_modules/.cache/terser-webpack-plugin/tmp/
Skipping Git submodules setup
Checking cache for default...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
$ cd view && npm run build
/bin/bash: line 78: npm: command not found
ERROR: Job failed: exit code 1