1

I want to deploy Angular 7 app(as static website) on S3 automatically using AWS Code pipeline. I have created Angular app and pushed to my git repo. I have created new AWS S3 bucket and created AWS Codepipline and integrated git repo

I am getting below error when aws code-pipelineb uilds the app: COMMAND_EXECUTION_ERROR: Error while executing command: ng build. Reason: exit status 1

enter image description here

I am using buildspect.yml file

version: 0.2

env:
    variables:
        S3_BUCKET: "<bucket name>"
        BUILD_ENV : "prod"

phases:
    install:
        runtime-versions:
            nodejs: 10
        commands:
            # install dependencies
            - echo Installng source NPM dependencies...
            - npm install npm@latest -g
            - npm install -g @angular/cli

    pre_build:
        commands:
            - echo Prebuild steps
            - npm install

    build:
        commands:
            # Builds Angular application. You can also build using custom environment here like mock or staging
            - echo Build started on `date`
            - ng build

    post_build:
        commands:
            # Clear S3 bucket.
            - aws s3 rm s3://${S3_BUCKET} --recursive
            - echo S3 bucket is cleared.
            # Copy dist folder to S3 bucket, As of Angular 6, builds are stored inside an app folder in distribution and not at the root of the dist folder
            - aws s3 cp dist s3://${S3_BUCKET} --recursive
            - echo Build completed on `date`

artifacts:
    files:
        - '/'
    discard-paths: yes
    base-directory: 'dist*'

I feel that code-build environment is not properly configured. I mean Nodejs and npm is not installed correctly. Please go through above yml file and help me identify if I am missing anything.

2
  • This is a bit of a guess, but try changing ng build to npm run build in your yml build step. Commented Jun 29, 2019 at 12:08
  • Tried that. But not working. same kind of error : COMMAND_EXECUTION_ERROR: Error while executing command: npm run build. Reason: exit status 1 Commented Jun 29, 2019 at 12:15

2 Answers 2

1

You are missing the build environment in your Buildspec.yml file.

Add this piece in and check if this helps -

build:
    commands:
        # Builds Angular application. You can also build using custom environment here like mock or staging
        - echo Build started on `date`
        - ng build --${BUILD_ENV}

This works for me perfectly!

Sign up to request clarification or add additional context in comments.

4 Comments

Ok. I will try. But when you say ‘This works for me perfectly’ does that mean you have exact same yml file?
It means, the build step that is included in my answer is from my yml file. And it works
I have tried that but still getting same error. Do you have any online turorial link which I can follow?
Can you share the build logs for the run? That might be helpful to figure out what's happening. Sorry I don't have any online links other than what you can google.
0

This yml file worked perfectly fine for me :

version: 0.2

env:
    variables:
        S3_BUCKET: "pratik-portfolio"
phases:
install:
    runtime-versions:
        nodejs: 10
    commands:
    - echo $CODEBUILD_SRC_DIR
    - npm install -y npm@latest
    - npm install -g @angular/cli
    - rm package-lock.json
pre_build:
    commands:
    - npm install
build:
    commands:
    - echo build started on `date`
    - ng build
    - ls -l -F
post_build:
    commands:
            # Clear S3 bucket.
            - aws s3 rm s3://${S3_BUCKET} --recursive
            - echo S3 bucket is cleared.
            - aws s3 cp dist/{Your app name} s3://${S3_BUCKET} --recursive
            - echo Build completed on `date`
artifacts:
    files:
        - '/'
    discard-paths: yes
    base-directory: 'dist*'
cache:
paths:
    - node_modules/

5 Comments

've been trying to do this and sadly each time I add an artifact definition in my buildspec.yml I get CLIENT_ERROR: no matching artifacts paths found. what am I missing? which should be the artifact definition inside my project build to allow place all files inside my s3 bucket.
Can you share your buildspec.yml?
Sure I can: version: 0.2 env: variables: S3_BUCKET: "myBucket-ui" APP_NAME: "myBucket-ui" BUILD_ENV : "prod"
phases: install: runtime-versions: nodejs: 10 commands: - apt-get install curl - curl -sL https://deb.nodesource.com/setup_10.x | bash - - apt-get install -y nodejs - apt-get update -y - apt-get install -y apt-transport-https - npm install -g @angular/cli - npm install
build: commands: - ng build --prod post_build: commands: - aws s3 sync dist/ s3://myBucket-ui --delete

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.