以下是我的步骤
steps:
-run:
name: Setup nvm and npm
command: |
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
export NVM_DIR=$HOME/.nvm
source $NVM_DIR/nvm.sh
nvm install 8.9 && nvm alias default 8.9
-run: npm install && npm run lint && npm test
第二步始终失败,并显示此错误消息
/bin/bash: npm: command not found
我检查过了
.bashrc
我可以看到以下几行被添加到文件的末尾
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
Circleci 2.0通过启动一个新的shell来调用step命令
#!/bin/bash -eo pipefail
如果我启动docker(
docker run -i -t buildpack-deps:xenial
)并应用第一步,然后通过
#哦/箱子/bash-eo管道故障
,我可以看到
npm
在路径上可用
我正在使用docker进行此项目
version: 2
jobs:
test_main:
docker:
- image: buildpack-deps:xenial
那么,为什么它在circleci 2.0环境中会失败呢?我如何确保
npm公司
是否可以从步骤1转到步骤2?
我试图添加
[ -s "$HOME/.bashrc" ] && \. "$HOME/.bashrc"
到
~/.bash_profile
(如果
。bashrc公司
由于非交互式/非登录shell而未执行)
要重现问题,可以运行
circleci build
用这个
.circleci/config.yml
文件
version: 2
jobs:
build:
docker:
- image: buildpack-deps:xenial
steps:
- run:
name: Setup nvm and npm
command: |
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
# Activate nvm
export NVM_DIR=$HOME/.nvm
touch $HOME/.nvmrc
source $NVM_DIR/nvm.sh
# Use node 8.9
nvm install 8.9 && nvm alias default 8.9
echo 8.9 > $HOME/.nvmrc
# Enable nvm in following steps
echo '[ -s "$HOME/.bashrc" ] && \. "$HOME/.bashrc"' >> $HOME/.bash_profile
# To fix npm install : "node-pre-gyp: Permission denied"
npm config set user 0
npm config set unsafe-perm true
npm install -g npx webpack webpack-cli jest
node --version
npm --version
- run: npm install
您将看到以下错误消息:
====>> npm install
#!/bin/bash -eo pipefail
npm install
/bin/bash: npm: command not found
Error: Exited with code 127
Step failed
Task failed