我正在尝试使用 AWS CodeBuild 安装 SonarQube。我使用 Nodejs: 10 作为运行时环境。当我将以下脚本作为构建规范运行时,出现以下错误?据我了解,问题是 NodeJS 环境不包含内置的 Maven。如果是这种情况,我该如何在 Node JS Env 中继续使用 Maven。预先感谢。
[Container] 2020/07/26 18:16:43 阶段上下文状态代码:COMMAND_EXECUTION_ERROR 消息:执行命令时出错:mvn test。原因:退出状态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/*
Maven 在 java 中可用:openjdk8。
您需要将相同的内容添加到您的 yml 中。
样本格式:
phases:
install:
runtime-versions:
java: openjdk8
build:
commands:
- mvn test
在
java: corretto11
下添加java: openjdk8
或java: openjdk11
或runtime-versions:
,maven将开始执行。
您可能需要使用项目特定的
settings.xml
进行maven构建,您可以轻松地在S3存储桶中提供它,然后在buildspec.yml的构建命令下引用它
我在 aws 配置中使用 corretto 而不是 openjdk,因为 aws 为 corretto 提供了 LTS。参考 - https://aws.amazon.com/corretto/faqs/