Gitlab-CI.yml does not share ratings

Asked

Viewed 50 times

0

I’m trying to automate a build using gitlab-ci.yml, but I’m having some problems. Apparently each Stage creates a new container of the image I chose. I guess I’m new to this CI/CD world so maybe the way I’m doing things isn’t the right way. Follow the script and the return obtained:

.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

When committing in dev when going from the first Stage to the second it cannot make use of the previously installed dependency. I know I can put everything in before_script but it will keep updating the distro and redoing the installation for all steps, but it is very slow.

Could anyone help me in how to proceed? Thank you.

Return

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

1 answer

0

Define the cache globally is the approach that allows you to share the dependencies generated between the Jobs. Here’s a example of Nodejs dependencies.

You’re already doing it, though is specifying the paths without the / in the end, then Gitlab is trying to cache files instead of a directory structure. Try setting your global cache as follows:

cache:
  paths:
    - view/dist/
    - view/node_modules/
  • Cool Eduardo, but looking at my error. How could I install the OS packages in the cache? (Stage: prepare from my yml).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.