Gitlab CI one before_script per stage

Hi there,

I’m trying to deploy a PWA to Heroku so I created a CI file that test the builds and a deploy script to push to Heroku. To push to Heroku I need ruby gem and for other stages I need nodejs.

I have a before_script that does a npm install -g yarn vue-cli quasar-cli@0.15.2 and I would like it not to be called on deploy stage is it possible ?

Here is my CI file

image: "node:8.9.0"

stages:
  - test
  - deploy

before_script:
  - npm install -g yarn vue-cli quasar-cli@0.15.2

cache:
  paths:
  - ./node_modules/

linter:
  stage: test
  script:
    - npm install
    - ./node_modules/.bin/eslint src/*

build-ios:
  stage: test
  script:
    - npm install
    - quasar build -t ios -m pwa -c

build-mat:
  stage: test
  script:
    - npm install
    - quasar build -t mat -m pwa -c

heroku:
  image: ruby:latest
  stage: deploy
  environment: production
  script:
    - gem install dpl
    - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_PRODUCTION_KEY
  only:
    - master