Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

749
Visualizações
Node and npm not getting recognized after getting installed from shell script in gitlab ci

I am trying to install nodejs using a shell script file named install-nodejs.sh in gitlab ci job in pipeline. Installation is successful and node displays the version while within install-nodejs.sh file but when I say node -v in gitlab-ci.yml file it doesn't recognize node command, what am I doing wrong?

I am created a shell script to install nodejs and set export path but still node is not getting recognized

install-nodejs.sh file code

#!/usr/bin/env bash
set -e

command -v node > /dev/null | NOT_INSTALLED=1
if [[ "$NOT_INSTALLED" != "1" ]]
then  
  mkdir /usr/local/nvm
  NVM_DIR="/usr/local/nvm"
  NODE_VERSION="10.12.0"
  NVM_INSTALL_PATH="$NVM_DIR/versions/node/v$NODE_VERSION"
  rm /bin/sh && ln -s /bin/bash /bin/sh
  curl --silent -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
  source ~/.nvm/nvm.sh
  nvm install $NODE_VERSION
  nvm alias default $NODE_VERSION
  nvm use default
  export NODE_PATH="$NVM_INSTALL_PATH/lib/node_modules"
  export PATH="$NVM_INSTALL_PATH/bin:$PATH"
fi

and gitlab.yml file code where i am calling this file

test_install_nodejs:
  <<: *default_job_template
  stage: build
  script:
    - ./scripts/install-nodejs.sh
    - node -v
    - npm -v
    - npm install -g newman

node -v in gitlab.yml file is not recognizing node but I can see the node installation is successful from shell file above.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Node is not found in the gitlab.yml file because the variables that you have defined in your install script are not available there. You can see that by yourself by calling echo $PATH just after ./scripts/install-nodejs.sh. You will see that PATH does not contain $NVM_INSTALL_PATH/bin.

The reason is that export is exporting the variables to the child process, not the parent. See Bash: export not passing variables correctly to parent.

You can make them available in the gitlab.yml file by using source:

test_install_nodejs:
  <<: *default_job_template
  stage: build
  script:
    - source ./scripts/install-nodejs.sh
    - node -v
    - npm -v
    - npm install -g newman

Note that I am assuming that install-nodejs.sh is exactly the one you have shown and does not end with exit (otherwise the yml script will end just after source).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda