【问题标题】:Angular prod build in Jenkins is failingJenkins 中的 Angular 产品构建失败
【发布时间】:2021-06-08 20:42:18
【问题描述】:

我有一个 Angular 应用程序,我正在尝试通过 Jenkins 进行部署。标准的 DEV 构建工作正常,但是当我执行 ng build --prod 时,它显示“ng: command not found”。

当使用npm run ng build -- --prod 运行命令时,它会显示“line 1: 6910 Killed”,然后是失败的命令

上周,我可以成功完成 prod 构建,但没有获取 environment.prod.ts 文件。今天,我遇到了上述两个错误之一。

我尝试了以下构建命令:

sh "ng build --prod"
sh "npm run ng build -- --configuration=production"
sh "npm run ng build -- --configuration production"
sh "npm run ng build -- --configuration=production --target=production --environment=prod"
sh "npm run ng build --configuration=production --target=production --environment=prod"
sh "npm run ng build -- --prod"
sh "npm run ng build -- --configuration prod"
sh "npm run ng build -- --configuration production"
sh "npm run ng build myCoolProjectName --prod --configuration=production"
sh "npm run ng build myCoolProjectName --prod --configuration production"
sh "npm run ng build --prod --configuration=production"
sh "npm run ng build --prod --configuration production"
sh "npm run ng build --configuration=production"

我在我的 Jenkins 服务器的 AWS EC2 实例上运行以下版本: 角 CLI:12.0.3, 节点:16.2.0, 包管理器:npm 7.13.0, 操作系统:linux x64

这是我的 Jenkinsfile 的重要部分:

 tools {
    //nodejs 'NodeJS 12.18.1'
    nodejs 'NodeJS 16.2.0'
  }

 stage('npm install') {
    steps {
            sh 'npm install'
    }
  }

  stage('Build') {
    steps {
      script{
        if("${ENVIRO}" == "prod") {
          PROFILE = "my-prod"
          sh "npm run ng build -- --prod"
        } else if("${ENVIRO}" == "qa"){
          PROFILE = "my-qa"
          sh "npm run ng build -- --configuration production"
        } 
        else {
          PROFILE = "my-dev"
          sh "npm run ng build"
        }
      }
    }
  }        

编辑: 我添加了内存使用情况的屏幕截图。红线末尾的摆动是我进行构建时(它失败了)。它似乎有很多可用的。

任何帮助将不胜感激,我很乐意提供更多信息。

干杯,

安迪

【问题讨论】:

    标签: angular jenkins npm


    【解决方案1】:

    第 1 行被杀很可能是因为云中的机器(在 Jenkins 上)内存不足。

    尝试向机器添加内存或终止占用内存的进程,以便 Angular 构建有更多内存可供操作。

    你也可以试试运行这个:

    // make node.js process take 1.5GB of space
    node --max_old_space_size=1500 ./node_modules/.bin/ng build -- --prod
    

    请参阅this 了解更多信息。

    【讨论】:

    • 我添加了来自服务器的屏幕截图。它似乎有很多可用的内存。
    • 它在本地工作吗?尝试在本地弄一个和Jenkins一样接近的环境,看看能不能复现。
    • 我可以成功地进行本地产品构建,是的。然后我手动将文件放在服务器上,一切正常。
    • max_old_space 命令对我不起作用,但是将我的 AWS EC2 实例从 t2.small 升级到 t2.medium 就可以了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2019-06-22
    • 2021-11-30
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2020-01-20
    • 1970-01-01
    相关资源
    最近更新 更多