简体   繁体   中英

Why Jenkins job for maven project throws error after specifying maven goals to trigger SonarQube analysis

I'm trying to run a Jenkins job that should be analyzing a java project built with a maven with gitlab source management using sonarqube scanner for maven... When I put into goals of that job the exact thing that is generated during the token tutorial creation withing SonarQube server, something like this:

mvn sonar:sonar \
  -Dsonar.host.url=http://***** \
  -Dsonar.login=****

It throws me this kind of a error:

[ERROR] Unknown lifecycle phase "mvn". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LifecyclePhaseNotFoundException

I don't know what is missing in my goal within a jenkins job or what should I add, thank you.

Screenshot of my maven project config:

构建屏幕

So I have eventually figured it up, to sum up.

You need to have the given project to be Maven project in Jenkins.

You need to have of course everything properly configured and integrated within SonarQube server and Jenkins, but that's now what is this question about.

Then you are adding to a build step only enviromental variables, for example

$SONAR_MAVEN_GOAL -Dsonar.host.url=$SONAR_HOST_URL

As is stated in given documentation

The most important thing is to have a maven project in jenkins. I tried this variant before and it was not working because it wasn't maven project in jenkins but freestyle project.

Example screenshot of build config:

CorrectBuildConfig

In Jenkins you no need to provide a mvn in goal execution.

Try just sonar:sonar \\ -Dsonar.host.url=http://***** \\ -Dsonar.login=**** by removing mvn in your top level maven task.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM