Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用codepipeline在AWS S3上部署Angular 7应用程序时出错_Angular_Amazon S3_Aws Codepipeline_Aws Codebuild - Fatal编程技术网

使用codepipeline在AWS S3上部署Angular 7应用程序时出错

使用codepipeline在AWS S3上部署Angular 7应用程序时出错,angular,amazon-s3,aws-codepipeline,aws-codebuild,Angular,Amazon S3,Aws Codepipeline,Aws Codebuild,我想使用AWS代码管道在S3上自动部署Angular 7应用程序(作为静态网站)。 我已经创建了Angular应用程序,并推到了我的git repo。 我创建了新的AWS S3 bucket,创建了AWS代码行和集成的git repo 当aws代码pipelineb构建应用程序时,我遇到以下错误: 命令执行错误:执行命令时出错:ng生成。原因:退出状态1 我正在使用buildspect.yml文件 version: 0.2 env: variables: S3_BUC

我想使用AWS代码管道在S3上自动部署Angular 7应用程序(作为静态网站)。 我已经创建了Angular应用程序,并推到了我的git repo。 我创建了新的AWS S3 bucket,创建了AWS代码行和集成的git repo

当aws代码pipelineb构建应用程序时,我遇到以下错误: 命令执行错误:执行命令时出错:ng生成。原因:退出状态1

我正在使用buildspect.yml文件

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*'
版本:0.2
环境:
变量:
S3_桶:“
构建环境:“产品”
阶段:
安装:
运行时版本:
nodejs:10
命令:
#安装依赖项
-echo正在安装源NPM依赖项。。。
-npm安装npm@latest-g
-npm安装-g@angular/cli
预构建:
命令:
-回显预构建步骤
-npm安装
建造:
命令:
#构建角度应用程序。您还可以在此处使用自定义环境(如模拟或登台)进行构建
-echo生成已于`日期'开始`
-ng构建
后期构建:
命令:
#清理S3铲斗。
-aws s3 rm s3://${s3_BUCKET}——递归
-回波S3桶被清除。
#将dist文件夹复制到S3 bucket,从6开始,构建存储在分发版的应用程序文件夹中,而不是dist文件夹的根目录中
-aws s3 cp dist s3://${s3_BUCKET}——递归
-echo生成于`日期'完成`
人工产品:
文件夹:
- '/'
放弃路径:是
基本目录:“dist*”

我觉得代码构建环境没有正确配置。我的意思是Nodejs和npm没有正确安装。请仔细阅读上面的yml文件,并帮助我确定是否遗漏了任何内容。

您在Buildspec.yml文件中遗漏了构建环境

加入这一部分,并检查这是否有助于-

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}

这对我来说太好了

这个yml文件对我来说非常好:

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/

这有点像猜测,但请尝试在yml构建步骤中将
ng build
更改为
npm run build
。尝试过了。但不起作用。相同类型的错误:命令执行错误:执行命令时出错:npm运行生成。原因:退出状态1Ok。我试试看。但是,当你说“这对我来说非常有效”时,这是否意味着你拥有完全相同的yml文件?这意味着,我的答案中包含的构建步骤来自我的yml文件。我试过了,但还是有同样的错误。你有我可以关注的在线旅游链接吗?你能分享跑步的构建日志吗?这可能有助于弄清发生了什么。很抱歉,除了你可以通过谷歌搜索的内容外,我没有任何其他在线链接。我一直在尝试这样做,不幸的是,每次我在buildspec.yml中添加工件定义时,我都会遇到CLIENT_错误:找不到匹配的工件路径。我错过了什么?哪个应该是我的项目构建中的工件定义,以允许将所有文件放在我的s3 bucket中。你可以共享你的buildspec.yml吗?当然可以:
version:0.2 env:variables:s3_bucket:“myBucket ui”APP_NAME:“myBucket ui”build_env:“prod”
阶段:安装:运行时版本:nodejs:10命令:-apt get install curl-curl-sLhttps://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安装
build:commands:-ng build--prod post_build:commands:-aws s3 sync dist/s3://myBucket ui--delete