我使用 nvm
将 Node 版本设置为 10.15.1
,并在下一个 run
步骤中返回到 6.1.0
。我尝试了几种变体,包括这个:https://www.cloudesire.com/how-to-upgrade-node-on-circleci-machine-executor/
我是否遗漏了一些明显的东西?我只需要每个 run
步骤记住我在第一个步骤中设置的 Node 版本,这样在这种情况下它们都将使用 10.15.1
。
这是我的工作流程中的工作:
dev:
environment:
BASH_ENV: run/env/test/.env
machine:
image: circleci/classic:latest
steps:
- checkout
- run:
name: Install node@10
command: |
set +e
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 10
nvm alias default 10
rm -rf ~./node-gyp
node -v # prints 10.15.1 as expected
- run:
name: Install yarn and rsync
command: |
node -v # prints 6.1.0
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
node -v # prints 6.1.0
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn rsync
- run:
name: Install node modules
command: |
node -v # prints 6.1.0
yarn install # this is what is failing because of the unexpected node version
- run:
name: Deploy to Dev Server
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then rsync -arhvz --exclude .git/ -e "ssh -o StrictHostKeyChecking=no" --progress \
./ ubuntu@xxx.xxx.xxx.xxx:/var/www/xxx/xxx/; fi
if [ "${CIRCLE_BRANCH}" == "master" ]; then ssh -o StrictHostKeyChecking=no ubuntu@xxx.xxx.xxx.xxx 'cd /var/www/xxx/xxx && pm2 restart all --update-env'; fi
最佳答案
通过将已安装的 Node 添加到 $PATH 来解决
示例:
- run:
name: 'Install Project Node'
command: |
set +x
source ~/.bashrc
nvm install 12
NODE_DIR=$(dirname $(which node))
echo "export PATH=$NODE_DIR:\$PATH" >> $BASH_ENV
关于node.js - CircleCI 忘记机器执行器上的 Node 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55027617/