nvm make node available in bitbucket pipeline script

62 views Asked by At

I created a shell script that installs a certain node version:

#!/bin/bash

set -e

mkdir nvmhome
export NVM_DIR="nvmhome"

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | NVM_DIR="nvmhome" bash

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

nvm install 20.9.0

node -v

npm -v

Then, in my bitbucket pipeline, I use it as follows:

# Some other pipeline steps & setup
- ./scripts/node-install.sh
- . "nvmhome/nvm.sh"; npm ci
- . "nvmhome/nvm.sh"; npm run build
# Some other pipeline steps & setup

For some reason, I always have to dot source the nvm before using npm/node. It's like the context it's lost between script lines in bitbucket.

This proves to be annoying in lots of scenarios. How can I load nvm such that it is available for the entirety of the bitbucket pipeline script of a certain step?

I cannot use a node base image for my pipeline.

0

There are 0 answers