COMMAND_EXECUTION_ERROR AWS CodeBuild - amazon-web-services

I am trying to setup a s3 bucket and github account to create a pipeline in aws codepipeline service. I am getting an error I can't seem to find. It seems to be related to the NPM Install command, but not sure why. Can someone help please?
COMMAND_EXECUTION_ERROR: Error while executing command: npm i. Reason: exit status 1
BuildSpec:
version: 0.2
env:
variables:
CACHE_CONTROL: "86400"
S3_BUCKET: "{{s3_bucket_url}}"
BUILD_FOLDER: "dist"
phases:
install:
runtime-versions:
nodejs: 16
commands:
- echo Installing source NPM dependencies...
- npm install
- npm install -g #angular/cli
build:
commands:
- echo Build started
- ng build
artifacts:
files:
- '**/*'
base-directory: 'dist*'
discard-paths: yes

Related

AWS CodeDeploy, Files getting removed from other folder

I have a code pipeline setup for React application. Whenever a new build is updated(In client folder) , the files(directories remain) are getting removed the server folder.
Tried seeing the event logs in code deploy, not able to get much info
could someone please help me with this?
appSpec.yml
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/client
hooks:
AfterInstall:
- location: scripts/after.sh
timeout: 300
runas: root
buildSpec.yml
version: 0.2
env:
variables:
NODE_ENV: "development"
phases:
install:
runtime-versions:
nodejs: 14
pre_build:
commands:
- npm install
build:
commands:
- npm run build-qa
artifacts:
type: zip
paths:
- './build/**/*'
- './appspec.yml'
- './scripts/**/*'
after.sh
#!/bin/bash
cd /home/ubuntu/client
echo '---Process started---'
echo '---Taking backup---'
sudo rm -r backup_*
sudo mv /home/ubuntu/client/deploy /home/ubuntu/client/backup_$(date +"%d-%m-%Y")
echo '---backup complete---'
echo '---renaming build---'
sudo mv /home/ubuntu/client/build /home/ubuntu/client/deploy
echo '---renaming complete---'
Edit: I was running two CI/CD pipelines (One for Frontend and other was backend) both running for the same EC2 instance, I was using the same deployment group and application for both the CI/CD which was causing the issue, later I created separate deployment application and group for each CI/CD which resolved . Thanks #Shivkumar Mallesappa for the lead

Copy build artifacts to s3 bucket using Buildspec.yml

I am trying to understand codebuild recently. I am trying to copy the build artifact to S3 bucket. I seen in one of my project's they are copying the files to S3 bucket using the command "aws s3 cp" instead of using the artifact phase.
Cant we achieve this using the artifact phase after post build phase instead of copying using "aws s3 cp" command in post build phase?
What is the purpose of the artifacts phase in Buildspec.yml?
Can we have Buildspec.yml without artifacts?
version: 0.2
env:
variables:
CACHE_CONTROL: "100"
S3_BUCKET: animation-project
BUILD_ENV: dev
phases:
install:
runtime-versions:
nodejs: 10
commands:
- echo Installing source NPM dependencies...
- echo environment printing ${STAGE}
- npm install
- npm install -g #angular/cli
build:
commands:
- echo Build started on `date`
- ng build --configuration=${BUILD_ENV}
# - ng test
- echo build completed
post_build:
commands:
- echo Post Build Started successfully on `date`
- aws s3 cp dist/* s3://${S3_BUCKET} --recursive --acl public-read --cache-control "max-age=${CACHE_CONTROL}"
- echo Build completed on `date`
artifacts:
files:
- '**/*'
base-directory: 'dist*'
discard-paths: yes
Thanks in advance for your answers.

Error while executing command: mvn test. Reason: exit status 1 - AWS

I am trying to install SonarQube using AWS CodeBuild. I am using a Nodejs: 10 as the run time environment. I am getting the below error when I run the below script as the build spec? As I understood, the issue is the NodeJS env does not contain Maven inbuilt. If that is the case, How can I proceed with Maven with in the Node JS Env. Thanks in advance.
[Container] 2020/07/26 18:16:43 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: mvn test. Reason: exit status 1
Issue occurs when it starts to execute -mvn test
buildspec.yml
version: 0.2
env:
secrets-manager:
LOGIN: SonarCloud:sonartoken
HOST: SonarCloud:HOST
Organization: SonarCloud:Organization
Project: prod/sonar:Project
phases:
install:
runtime-versions:
nodejs: 10
pre_build:
commands:
- npm install
- apt-get update
- apt-get install -y jq
- wget http://www-eu.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
- tar xzf apache-maven-3.5.4-bin.tar.gz
- ln -s apache-maven-3.5.4 maven
- wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip
- unzip ./sonar-scanner-cli-3.3.0.1492-linux.zip
- export PATH=$PATH:/sonar-scanner-3.3.0.1492-linux/bin/
build:
commands:
- mvn test
- mvn sonar:sonar -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization
- sleep 5
- curl https://sonarcloud.io/api/qualitygates/project_status?projectKey=$Project >result.json
- cat result.json
- if [ $(jq -r '.projectStatus.status' result.json) = ERROR ] ; then $CODEBUILD_BUILD_SUCCEEDING -eq 0 ;fi
- echo Build started on `date`
- echo Compiling the Node.js code
post_build:
commands:
- echo Build completed on `date`
artifacts:
files:
- server.js
- package.json
- controller/*
Maven is available in java : openjdk8.
You need to add the same to your yml.
Sample format :
phases:
install:
runtime-versions:
java: openjdk8
build:
commands:
- mvn test
Add either java: corretto11 or java: openjdk8 or java: openjdk11 under runtime-versions: and maven will start executing.
Probably you might need to use your project specific settings.xml for maven build, which you can easily provide in a S3 bucket and then refer it under build commands of buildspec.yml
I'm using corretto rather than openjdk in my aws configuration, as aws provide LTS for corretto. Reference - https://aws.amazon.com/corretto/faqs/

CodeBuild + ReactNative + Expo Web - This build image requires selecting at least one runtime version

Trying to use CodeBuild for the first time, pulling data from CodeCommit. But I'm having issues with my buildspec. This is the code I have on it so far:
version: 0.2
phases:
INSTALL:
runtime-versions:
nodejs: 10
commands:
- npm install
PRE_BUILD:
commands:
- npm install --quiet --global expo-cli
- >
if [ -f yarn.lock ]; then
yarn
elif [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then
npm ci
else
npm install
fi
BUILD:
commands:
- expo build:web
artifacts:
baseDirectory: web-build
files:
- '**/*'
name:
myname-$(date +%Y-%m-%d)
cache:
paths:
- node_modules/**/*
- $(npm root --global)/**/*
I have already added the runtime for nodejs 10, it had stopped to trigger this error, but now it kicked again. Does anyone know how to properly tweak it for React-Native web projects?
I believe the phase names are case sensitive, so change them to install, pre_build and build.

Deploy nuxt on AWS amplify console

I have an aws amplify project built on top of nuxt. I'm trying to setup CI using amplify console. My build keeps failing in deploy stage, for some reason the artifacts aren't being created or can't be found:
Here's my amplify.yml file:
version: 0.1
backend:
phases:
build:
commands:
- '# Execute Amplify CLI with the helper script'
- amplifyPush --simple
frontend:
phases:
preBuild:
commands:
- npm install
build:
commands:
- npm run generate
artifacts:
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*
If I run npm run generate locally then my app is built and can be found in the dist folder without any problems.
did anyone manage to successfully deploy an amplify/nuxt app using the amplify console?
Thanks
Update 1
change the buildspec:
version: 0.1
frontend:
phases:
preBuild:
commands:
- npm ci
build:
commands:
- npm run generate
artifacts:
# IMPORTANT - Please verify your build output directory
baseDirectory: dist
files:
- '**/*'
cache:
paths:
- node_modules/**/*