I created a code pipeline with very simple code and connected to codecommit. tried to build it but it is failing at codebuild step stating error executing npm install. Am I missing something? Sorry I was new to this codebuild/ codepipeline.
Below is the log for codebuild failure:
[Container] 2019/02/15 11:47:39 Waiting for agent ping
[Container] 2019/02/15 11:47:40 Waiting for DOWNLOAD_SOURCE
[Container] 2019/02/15 11:47:40 Phase is DOWNLOAD_SOURCE
[Container] 2019/02/15 11:47:40 CODEBUILD_SRC_DIR=/codebuild/output/src501317273/src
[Container] 2019/02/15 11:47:40 YAML location is /codebuild/output/src501317273/src/buildspec.yml
[Container] 2019/02/15 11:47:40 Processing environment variables
[Container] 2019/02/15 11:47:40 Moving to directory /codebuild/output/src501317273/src
[Container] 2019/02/15 11:47:40 Registering with agent
[Container] 2019/02/15 11:47:40 Phases found in YAML: 1
[Container] 2019/02/15 11:47:40 BUILD: 2 commands
[Container] 2019/02/15 11:47:40 Phase complete: DOWNLOAD_SOURCE Success: true
[Container] 2019/02/15 11:47:40 Phase context status code: Message:
[Container] 2019/02/15 11:47:40 Entering phase INSTALL
[Container] 2019/02/15 11:47:40 Phase complete: INSTALL Success: true
[Container] 2019/02/15 11:47:40 Phase context status code: Message:
[Container] 2019/02/15 11:47:40 Entering phase PRE_BUILD
[Container] 2019/02/15 11:47:40 Phase complete: PRE_BUILD Success: true
[Container] 2019/02/15 11:47:40 Phase context status code: Message:
[Container] 2019/02/15 11:47:41 Entering phase BUILD
[Container] 2019/02/15 11:47:41 Running command npm install
sh: 1: npm: not found
[Container] 2019/02/15 11:47:41 Command did not exit successfully npm install exit status 127
[Container] 2019/02/15 11:47:41 Phase complete: BUILD Success: false
[Container] 2019/02/15 11:47:41 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: npm install. Reason: exit status 127
[Container] 2019/02/15 11:47:41 Entering phase POST_BUILD
[Container] 2019/02/15 11:47:41 Phase complete: POST_BUILD Success: true
[Container] 2019/02/15 11:47:41 Phase context status code: Message:
[Container] 2019/02/15 11:47:41 Expanding base directory path: .
[Container] 2019/02/15 11:47:41 Assembling file list
[Container] 2019/02/15 11:47:41 Expanding .
[Container] 2019/02/15 11:47:41 Expanding artifact file paths for base directory .
[Container] 2019/02/15 11:47:41 Assembling file list
[Container] 2019/02/15 11:47:41 Expanding post-saml.yaml
[Container] 2019/02/15 11:47:41 Skipping invalid artifact path post-saml.yaml
[Container] 2019/02/15 11:47:41 Expanding beta.json
[Container] 2019/02/15 11:47:41 Found 1 file(s)
[Container] 2019/02/15 11:47:41 Phase complete: UPLOAD_ARTIFACTS Success: true
[Container] 2019/02/15 11:47:41 Phase context status code: Message:
My buildspec.yml file looks like this:
version: 0.0
environment_variables:
plaintext:
"INPUT_FILE": "serverless.yml"
"S3_BUCKET": ""
containers:
LambdaFunctions:
phases:
during_build:
commands:
- npm install
- aws cloudformation package --template $INPUT_FILE --s3-bucket $S3_BUCKET --output-template post-saml.yaml
artifacts:
files:
- post-saml.yaml
- beta.json
The error message is a few lines down your logs : sh: 1: npm: not found
.
This means the npm command is not available in the build environment. Did you correctly select a nodejs
build ?
When you create a build environment, you have to specify the operating system and the runtime. It is very unlikely here that you did not specifcy nodejs
as runtime.
See step by step guide here : https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started.html#getting-started-create-build-project
See documentation here : https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
And see a screenshot from my console here :
Just posting this here in case someone else comes across it in the future. OP buildspec.yaml
should work if updated to the following
BuildSpec Reference
Changelog:
version: 0.2
env:
variables:
INPUT_FILE: "serverless.yml"
S3_BUCKET: ""
phases:
install:
runtime-versions:
nodejs: 10
commands:
- npm install
build:
commands:
- aws cloudformation package --template $INPUT_FILE --s3-bucket $S3_BUCKET --output-template post-saml.yaml
artifacts:
files:
- post-saml.yaml
- beta.json
I had the same issue. To see the actual issue please check the build logs carefully. It's not the error shown in red, but few line above this.
(1) Something to do with permission od the code build service role. I assigned the administration access temporarily and it worked but failed due to different reason. To check it, try to execute the simple cloud-formation command like ‘aws cloudformation list-stacks’ only ( try it with inline command option or leave this command only and see it works.
(2) The issue with mine was a samtemplate file (I was trying with C#), in your case serverless.yml. It was creating a build file in one location, but my samtemplate referring to a different location. if possible, try the same command from you AWS CLI in you local machine
There may be a chance you have selected a wrong Os/image etc.. Check https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started-create-build-project-console.html
Adding as it may help someone. I received an error that read:
/codebuild/output/tmp/script.sh: 4: ‘npm: not found
It turned out this was due to the quotation marks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With