在GitLab-CI中使用NVM安装特定的Node.js版本

4

当我尝试使用gitlab-ci安装NVM时,我收到以下错误消息:

.gitlab-ci.yml文件


stages:
    - test

Testing:
    tags: 
    - docker 
    stage: test
    image: ubuntu:18.04
    before_script: 
    - apt-get update 
    - apt-get install curl  -y

    # Install Node Version Manager (NVM) so we can change the node version 
    - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
    - nvm --version 

错误信息:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
    % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                    Dload  Upload   Total   Spent    Left  Speed
100 13527  100 13527    0     0  99463      0 --:--:-- --:--:-- --:--:-- 99463
=> Downloading nvm as script to '/root/.nvm'
=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
$ nvm --version
/bin/bash: line 116: nvm: command not found
ERROR: Job failed: exit code 1

当我尝试使用exec bash重新加载gitlab-ci中的终端时,gitlab任务会过早地结束,并且不运行脚本的其余部分。

如何在gitlab-ci中安装和使用nvm?

1个回答

7

更新脚本以将nvm命令加载到您的终端中。". ~/.nvm/nvm.sh"

    # Install Node Version Manager (NVM) so we can change the node version 
    - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
    - ". ~/.nvm/nvm.sh"
    - nvm --version 

我不得不在“。~ / .nvm / nvm.sh”后面添加“--no-use”,否则它会立即停止作业。 - David S.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接