nvm icon indicating copy to clipboard operation
nvm copied to clipboard

nvm errors out with exit status 3 in aws code build

Open NiteshBagle123 opened this issue 2 years ago • 11 comments

Error message - [Container] 2023/06/02 12:24:31 Command did not exit successfully . "$NVM_DIR/nvm.sh" && nvm use 14.17.0 exit status 3

We have aws pipeline with nodejs runtime in it. We have done below -

  1. Installed nvm and all required node version within pipeline and copied the same in S3 bucket (reason for copy as we are getting 5xx error from nvm, caching mechanism to not install again for every build in cicd pipeline). Script below -
version: 0.2
env:
  shell: bash
phases:
  install:
    runtime-versions:
      nodejs: 14
    commands:
      - /usr/local/bin/aws --version
  pre_build:
    commands:
      - bash ./sh-files/retry.sh 3 "curl -o install.sh --write-out "%{http_code}" https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh"
      - export NVM_DIR="$HOME/.nvm"
      - '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
      - '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"'
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 12.22.2"
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 14.17.0"
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 10"
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 14.17.6"
      - aws s3 cp $HOME/.nvm s3://<bucket_name>/cicd-pipeline-nb/dependencies/.nvm --region us-west-2 --recursive
      - echo successfully copied dependencies code

It works fine in aws code build. But when runs other script to copy the S3 .nvm folder in aws code build(other pipeline) instance causes exist 3 issue. Refer script below -

  version: 0.2
  env:
    shell: bash
  phases:
    install:
      on-failure: ABORT
      runtime-versions:
        nodejs: 12
      commands:
        - aws s3 cp s3://<bucket_name>/cicd-pipeline-nb/customer-customization/ . --region us-west-2 --recursive
        - aws s3 cp s3://<bucket_name>/cicd-pipeline-nb/dependencies/.nvm $HOME/.nvm --region us-west-2 --recursive
        - echo ENABLE_SCANS Value $ENABLE_SCANS
        - export NVM_DIR="$HOME/.nvm"
        - '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
        - '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"'
        - . "$NVM_DIR/nvm.sh" && nvm use 14.17.0
        - export NODE_OPTIONS="--max-old-space-size=8192"
        - node --version
        - echo Installing yarn...

NiteshBagle123 avatar Jun 02 '23 12:06 NiteshBagle123

Script in pipeline 1 (where we download all nvm, node and copy in aws s3 bucket) -

version: 0.2
env:
  shell: bash
phases:
  install:
    runtime-versions:
      nodejs: 14
    commands:
      - /usr/local/bin/aws --version
  pre_build:
    commands:
      - bash ./sh-files/retry.sh 3 "curl -o install.sh --write-out "%{http_code}" https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh"
      - export NVM_DIR="$HOME/.nvm"
      - '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
      - '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"'
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 12.22.2"
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 14.17.0"
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 10"
      - . "$NVM_DIR/nvm.sh" && bash ./sh-files/retry.sh 3 "nvm install 14.17.6"
      - aws s3 cp $HOME/.nvm s3://<bucket_name>/cicd-pipeline-nb/dependencies/.nvm --region us-west-2 --recursive
      - echo successfully copied dependencies code

NiteshBagle123 avatar Jun 02 '23 13:06 NiteshBagle123

Script which copies S3 .nvm folder in root folder of aws code build and then does nvm use of specific node version (pipeline 2) -

  version: 0.2
  env:
    shell: bash
  phases:
    install:
      on-failure: ABORT
      runtime-versions:
        nodejs: 12
      commands:
        - aws s3 cp s3://<bucket_name>/cicd-pipeline-nb/customer-customization/ . --region us-west-2 --recursive
        - aws s3 cp s3://<bucket_name>/cicd-pipeline-nb/dependencies/.nvm $HOME/.nvm --region us-west-2 --recursive
        - echo ENABLE_SCANS Value $ENABLE_SCANS
        - export NVM_DIR="$HOME/.nvm"
        - '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"'
        - '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"'
        - . "$NVM_DIR/nvm.sh" && nvm use 14.17.0
        - export NODE_OPTIONS="--max-old-space-size=8192"
        - node --version
        - echo Installing yarn...

NiteshBagle123 avatar Jun 02 '23 13:06 NiteshBagle123

Note that the scripts were REALLY unclear with single backticks; i edited it to triple backticks so newlines render properly.

ljharb avatar Jun 02 '23 16:06 ljharb

Where exactly does the failure happen? What's the failure output?

ljharb avatar Jun 02 '23 16:06 ljharb

@ljharb Failure happing in aws code build in cicd pipeline. Above pasted shell scripts needed install third party dependencies but same working in one code build but when copied in the same in other aws code build it is throwing exit 3 error. Please assist

NiteshBagle123 avatar Jun 05 '23 04:06 NiteshBagle123

@ljharb Failure output mentioned below - Error message - [Container] 2023/06/02 12:24:31 Command did not exit successfully . "$NVM_DIR/nvm.sh" && nvm use 14.17.0 exit status 3

NiteshBagle123 avatar Jun 05 '23 04:06 NiteshBagle123

is it the sourcing that exits 3, or the nvm use?

ljharb avatar Jun 05 '23 05:06 ljharb

@ljharb issue when downloading node using nvm.

NiteshBagle123 avatar Jun 05 '23 06:06 NiteshBagle123

that command doesn't download node. it sources nvm.sh, and then uses an already-installed version.

ljharb avatar Jun 05 '23 16:06 ljharb

@ljharb Please assist why exit status 3 error?

NiteshBagle123 avatar Jun 05 '23 17:06 NiteshBagle123

I have no idea. You told me that . "$NVM_DIR/nvm.sh" && nvm use 14.17.0 exited 3. I'm asking if it's the . "$NVM_DIR/nvm.sh" or the nvm use 14.17.0 that exited with 3.

Perhaps you're setting the -e shell option? That's inadvisable if so - try disabling it.

ljharb avatar Jun 05 '23 17:06 ljharb