You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CircleCI配置初始化阶段如何指定使用Node.js 12版本

方案1:使用已有Node orb直接指定版本

你已经引入了官方的circleci/node orb,不需要手动安装nvm切换版本,直接给node/install步骤传入version参数即可指定安装的Node版本,只需给原有配置加一行参数,同时删掉冗余的nvm相关操作步骤即可,修改后的完整配置如下:

version: 2.1
orbs:
  node: circleci/node@4.1.0
  aws-cli: circleci/aws-cli@2.0.3
  eb: circleci/aws-elastic-beanstalk@2.0.1
jobs:
  build:
    docker:
      - image: "cimg/base:stable"
    steps:
      - node/install:
          version: '12'
      - checkout
      - aws-cli/setup
      - eb/setup
      - run:
          name: Check current version of node
          command: node -v
      - run:
          name: Back-End Install
          command: |
            npm run backend:install
      - run:
          name: Front-End Install
          command: |
            npm run frontend:install
      - run:
          name: Back-End Build
          command: |
            npm run backend:build
      - run:
          name: Front-End Build
          command: |
            npm run frontend:build
      - run:
          name: Back-End Deploy
          command: |
            npm run backend:deploy
      - run:
          name: Front-End Deploy
          command: |
            npm run frontend:deploy

方案2:直接使用预装Node 12的官方Docker镜像

可以直接把你当前用的cimg/base:stable镜像换成对应Node版本的cimg/node:12镜像,连node/install步骤都可以完全省略,环境初始化速度更快,精简后的配置如下:

version: 2.1
orbs:
  aws-cli: circleci/aws-cli@2.0.3
  eb: circleci/aws-elastic-beanstalk@2.0.1
jobs:
  build:
    docker:
      - image: "cimg/node:12"
    steps:
      - checkout
      - aws-cli/setup
      - eb/setup
      - run:
          name: Check current version of node
          command: node -v
      - run:
          name: Back-End Install
          command: |
            npm run backend:install
      - run:
          name: Front-End Install
          command: |
            npm run frontend:install
      - run:
          name: Back-End Build
          command: |
            npm run backend:build
      - run:
          name: Front-End Build
          command: |
            npm run frontend:build
      - run:
          name: Back-End Deploy
          command: |
            npm run backend:deploy
      - run:
          name: Front-End Deploy
          command: |
            npm run frontend:deploy

内容的提问来源于stack exchange,提问作者Arefe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 19:51:02