执行命令时,代码构建失败并显示错误:npm install。原因:退出状态127

问题描述 投票:2回答:1

我用非常简单的代码创建了一个代码管道,并连接到codecommit。试图建立它,但它在codebuild步骤失败说明执行npm install错误我错过了什么。对不起,我是这个codebuild / codepipeline的新手

下面是代码生成失败的日志

[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: 

我的buildspec.yml文件看起来像这样

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

在此先感谢您的帮助

amazon-web-services npm aws-codebuild
1个回答
3
投票

错误信息是您日志的几行:sh: 1: npm: not found

这意味着npm命令在构建环境中不可用。你正确选择了nodejs构建吗?

创建构建环境时,必须指定操作系统和运行时。这里你不太可能没有将nodejs指定为运行时。

请参阅此处的分步指南:https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started.html#getting-started-create-build-project

请参阅此处的文档:https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html

从我的控制台看到截图:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.