Angular 在 Jenkins 中构建产品失败

Angular prod build in Jenkins is failing

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

当 运行 带有 npm run ng build -- --prod 的命令时,它会显示“第 1 行:6910 被杀死”,然后是失败的命令

上周,我可以成功完成产品构建,但没有获取 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 实例上 运行 以下版本: Angular命令行界面:12.0.3, 节点:16.2.0, 包管理器:npm 7.13.0, OS: 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"
        }
      }
    }
  }        

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

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

干杯,

安迪

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

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

你也可以试试运行这个:

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

有关详细信息,请参阅