【问题标题】:Review of gitlab CI using yml使用 yml 回顾 gitlab CI
【发布时间】:2022-04-23 01:59:09
【问题描述】:

您好,我正在使用以下 gitlab yml 文件来设置我的管道。该项目是一个 Maven Java 项目。但我无法成功运行所有步骤。这是gitlab yml:

image: maven:3.5-jdk-8

variables:
   MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
   MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"

include:
    - template: Security/SAST.gitlab-ci.yml

cache:
  paths:
    - .m2/settings.xml

# Define stages
#   Stages group various steps into one block,
#   if any step fails, the entire stage fails
stages:
  - validate
  - compile
  - SonarQube
  - test
  
validate: 
  stage: validate
  script:
    - mvn validate

compile:
  stage: compile
  script:
    - mvn $MAVEN_CLI_OPTS compile
  
sonarqube-check:
  image: maven:3.6.3-jdk-11
  stage: SonarQube 
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"
  script:
    - mvn sonar:sonar -Dsonar.projectKey=key -Dsonar.host.url=url -Dsonar.login=id
  allow_failure: true

spotbugs-sast:
  variables:
    COMPILE: "false"
    SECURE_LOG_LEVEL: "debug"
  artifacts:
    reports:
      sast: gl-sast-report.json


#spotbugs-sast:
#  variables:
#    SECURE_LOG_LEVEL: "debug"
    #FAIL_NEVER: 1

test:
  image: maven:3.5-jdk-8
  stage: test
  script:
    - mkdir -p /opt/path/conf/project/
    - echo ${CI_PROJECT_DIR}
    - cp "${CI_PROJECT_DIR}/project.properties" "/opt/path/conf/project/"
    - mvn $MAVEN_CLI_OPTS test -B

但我分阶段遇到错误:sonarqube、spotbug-sast 和测试。

  1. 在 sonarqube 中,显示错误为:无法通过 jar 文件列表解析项目依赖项:

无法解析以下工件:webpay:webpay-client:jar:4.0.4, mpienhanced:mpienhanced:jar:1.0.0, webpay:webpay-mpi:jar:4.3.9, webpay:matrix-mpi :jar:1.27.4, webpay:vbv-matrix:jar:1.12.1, webpay:xercesImpl:jar:2.12.0, webpay:xss4j:jar:0.0.1, webpay:xmlParserAPIs:jar:2.11.0, webpay :webpay-mpi-util:jar:4.2.2

  1. 在 spotbugs-sast 中,我收到以下错误: [INFO] [查找安全漏洞] [2022-01-13T10:41:39Z] ▶ 找到 1 个可分析项目。 [FATA] [查找安全漏洞] [2022-01-13T10:41:39Z] ▶ lstat /root/.m2/repository: 没有这样的文件或目录

  2. 在测试阶段,它无法从配置文件中提到的路径获取属性文件。我试图将属性文件放在所有地方并指定路径,但没有成功。

有人可以帮助解决我的问题吗?提前致谢。 如果需要任何其他信息,请告诉我。

【问题讨论】:

  • 您是否使用不同的图像运行每个阶段?
  • 不,我也尝试过使用全局图像来运行每个阶段,但不是运气
  • 好的,您要先尝试SonarQube 阶段吗?你能试试this的方法吗?
  • 尝试了给出的答案,但仍然遇到相同的错误。未能执行目标。
  • 任何帮助将不胜感激。提前致谢。

标签: java maven gitlab continuous-integration yaml


【解决方案1】:

您可以尝试返回 documentation example 并对其进行调整,以逐步使其与您的问题相同。

但请注意:spotbugs-sast 不会再分析 Java。

GitLab 14.10(2022 年 4 月)

在 SAST 中更快、更轻松地进行 Java 扫描

GitLab 静态应用程序安全测试 (SAST) 现在使用 Semgrep 扫描 Java 代码,建立在之前对 Go (introduced in GitLab 14.4)JavaScript, TypeScript, and Python (introduced in GitLab 13.12) 的支持之上。

基于 Semgrep 的分析器运行速度明显更快,在我们的测试中,它比基于 SpotBugs 的现有分析器快 7 倍。 它也不需要在扫描之前编译你的代码,所以它比 SpotBugs 使用起来要简单得多。

静态分析和漏洞研究团队合作将规则转换为 Semgrep 格式,同时保留大多数现有规则。 我们还在转换规则时更新、改进和测试了规则。

如果您使用the GitLab-managed SAST template (SAST.gitlab-ci.yml),现在只要找到 Java 代码,Semgrep 和 SpotBugs 就会运行。 在 GitLab Ultimate 中,安全仪表板结合了来自两个分析器的结果,因此您不会看到重复的漏洞报告。

在 GitLab 15.0 中,作为 we announced,我们将更改 the GitLab-managed SAST template (SAST.gitlab-ci.yml) 以仅运行基于 Semgrep 的 Java 代码分析器基于 SpotBugs 的分析器仍将扫描其他 JVM 语言,例如 Groovy、Kotlin 和 Scala

如果您对新的基于 Semgrep 的 Java 扫描有任何疑问、反馈或问题,请file an issue,我们很乐意为您提供帮助。

请参阅 DocumentationIssue

【讨论】:

    猜你喜欢
    • 2018-12-15
    • 2017-08-27
    • 2019-03-09
    • 2021-11-06
    • 1970-01-01
    • 2022-10-11
    • 2022-01-19
    • 2021-06-22
    • 2018-09-28
    相关资源
    最近更新 更多