Search code examples
amazon-web-servicesaws-codepipeline

NVM not found in AWS CI-CD Pipeline


I am new to create a pipeline in aws. I want to create a ci-cd pipeline for my nuxt project. I create a yml file in which I want to install nvm and then install node version 12.18.3

The problem is I am getting the nvm not found error.

Can you please check and let me know if there is any error in my yml file:

version: 0.2
phases:
  install:
   commands:
     - echo Installing nvm...
     - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
     - export NVM_DIR="$HOME/.nvm"
     - '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
     - '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"'
  pre_build:
    commands:
      #install dependencies
      - echo Installing node...
      - nvm install 12.18.3
      - echo Installing npm...
      - npm install
  build:
    commands:
      #build
      - echo building...
      - npm run generate
artifacts:
  files:
    - '**/*'
 base-directory: dist
cache:
  paths:
    - node_modules/**/*

Thank you.


Solution

  • Working Solution

    For some reason, It doesn't recognize nvm in the next line. I did not get a chance to investigate it further. The following configuration works. The idea is to set the nvm configurations and install node in the same line.

    version: 0.2
    phases:
      install:
        commands:
          - echo Installing nvm...
          - curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
          - export NVM_DIR="$HOME/.nvm"
          - '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
          - '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"'
      pre_build:
        commands:
          #install dependencies
          - . "$NVM_DIR/nvm.sh" && nvm install 12.18.3 && echo "node installed by arun"
          - echo Installing node...
          #- nvm install 12.18.3
          - echo Installing npm...
          - npm install
      build:
        commands:
          #build
          - echo building...
          - npm run generate
    cache:
      paths:
        - node_modules/**/*
    

    Troubleshoot in local environment.

    In order to troubleshoot the buildspec.yaml, you can run the build locally. here is how to run the buildspec locally.