[英]Gitlab CI/CD running fine on local but not on gitlab
我正在嘗試在我的 java maven 項目上構建 gitlab CI/CD 管道。 我在本地機器上嘗試了所有階段,它們都成功通過了,但是當我在 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=XX.XX.XXX.XXX \ -Dsonar.host.url=http://XX.XX.XXX.XXX \ -Dsonar.login=XX.XX.XXX.XXX -X
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:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test -B
階段驗證和編譯運行良好,但我在聲納檢查和 spotbugs sast 中收到警告。 在我的本地也運行良好。 在 sonarqube 檢查錯誤是:
Error resolving version for plugin ' -Dsonar.host.url=http://XX.XX.XXX.XXX' from the repositories [local (/builds/XX.XX.XXX.XXX/.m2/repository), central (https://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository -> [Help 1]
org.apache.maven.plugin.version.PluginVersionResolutionException: Error resolving version for plugin ' -Dsonar.host.url=http://XX.XX.XXX.XXX' from the repositories [local (/builds/XXXX/XXXXX/.m2/repository), central (https://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository
對於 spotbugs-sast 警告,錯誤是:
[FATA] [Find Security Bugs] ▶ lstat /root/.m2/repository: no such file or directory
我花了很多時間來解決這個問題並等待項目在所有階段成功編譯,但每次我都很失望。 請幫忙。 我很感激你的時間。
Maven 將字符串-Dsonar.host.url=http://XX.XX.XXX.XXX
識別為需要解析的插件/目標。
這是由腳本中的\
引起的。
代替:
mvn sonar:sonar \ -Dsonar.projectKey=XX.XX.XXX.XXX \ -Dsonar.host.url=http://XX.XX.XXX.XXX \ -Dsonar.login=XX.XX.XXX.XXX -X
嘗試:
mvn sonar:sonar -Dsonar.projectKey=XX.XX.XXX.XXX -Dsonar.host.url=http://XX.XX.XXX.XXX -Dsonar.login=XX.XX.XXX.XXX -X
我假設您從以下格式復制了該命令:
mvn sonar:sonar \
-Dsonar.projectKey=XX.XX.XXX.XXX \
-Dsonar.host.url=http://XX.XX.XXX.XXX \
-Dsonar.login=XX.XX.XXX.XXX -X
在 bash 中,如果命令包含換行符,則\
必須位於行尾,以便將其識別為一個命令。 但是,如果將其轉換為一行,則需要將其刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.