执行命令时出错:mvn测试。原因:退出状态1-AWS

时间:2020-07-26 18:38:45

标签: amazon-web-services maven aws-code-deploy aws-codepipeline aws-codebuild

我正在尝试使用AWS CodeBuild安装SonarQube。我正在使用Nodejs:10作为运行时环境。当我运行以下脚本作为构建规范时,出现以下错误?据我了解,问题在于NodeJS env不包含内置的Maven。如果是这种情况,如何在Node JS Env中继续使用Maven。预先感谢。

[容器] 2020/07/26 18:16:43阶段上下文状态代码:COMMAND_EXECUTION_ERROR消息:执行命令时出错:mvn测试。原因:退出状态1

问题开始执行-mvn test

时发生

buildspec.yml

version: 0.2
env:
  secrets-manager:
    LOGIN: SonarCloud:sonartoken
    HOST: SonarCloud:HOST
    Organization: SonarCloud:Organization
    Project: prod/sonar:Project
phases:
  install:
    runtime-versions:
      nodejs: 10  
  pre_build:
    commands:
      - npm install
      - apt-get update
      - apt-get install -y jq
      - wget http://www-eu.apache.org/dist/maven/maven-3/3.5.4/binaries/apache-maven-3.5.4-bin.tar.gz
      - tar xzf apache-maven-3.5.4-bin.tar.gz
      - ln -s apache-maven-3.5.4 maven
      - wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-3.3.0.1492-linux.zip
      - unzip ./sonar-scanner-cli-3.3.0.1492-linux.zip
      - export PATH=$PATH:/sonar-scanner-3.3.0.1492-linux/bin/
  build:
    commands:
      - mvn test     
      - mvn sonar:sonar -Dsonar.login=$LOGIN -Dsonar.host.url=$HOST -Dsonar.projectKey=$Project -Dsonar.organization=$Organization
      - sleep 5
      - curl https://sonarcloud.io/api/qualitygates/project_status?projectKey=$Project >result.json
      - cat result.json
      - if [ $(jq -r '.projectStatus.status' result.json) = ERROR ] ; then $CODEBUILD_BUILD_SUCCEEDING -eq 0 ;fi
      - echo Build started on `date`
      - echo Compiling the Node.js code
  post_build:
    commands:
      - echo Build completed on `date`
artifacts:
  files:
    - server.js
    - package.json
    - controller/*

1 个答案:

答案 0 :(得分:1)

Maven在Java中可用:openjdk8。

您需要将其添加到您的yml中。

示例格式:

phases:
  install:
    runtime-versions:
      java: openjdk8

  build:
    commands:
      - mvn test