简体   繁体   中英

SonarQube: Check if a project with the same key already exists while first analysis/build

I am building my projects with Jenkins and analyze them with SonarQube.

The problem I am trying to fix without writting my own Plugin is the following:

  • 1.) Jenkins starts a build of a new project (never built or analyzed an SonarQube before)
  • 2.) SonarQube analysis is triggered
  • 3.) SonarQube shell check if a project with the same key already exists
  • 4a.) If it already exists: Abort analysis and throw error message
  • 4b.) If it not exist: Continue the analysis as a normal analysis

Or in other words: If a Project is analyzed for the first time, I want SonarQube to make sure that there is no other project already existing with the same key this new project uses. The goal is to avoid overwritting existing projects by a complete other project If a project has been already analyized and the new analysis would be a like "updating the old results" i don't want any error message to show up.

Can i simply install a plugin? Must i change things within the pom.xml? Is there a way? And if yes: how does it work?

(I know the possibility to get the buildnumber of the last successful build in Jenkins. And if it would be greater or equal 1 there would be no reason for my check anymore. If it's not: i need my check)

Thanks for your help :)

You can use the /api/resources?resource=project-key Web Service from a script to check if the given project key already exists (if not, the WS will answer with a 404).

However, as @andre-stannek said: in the end it is your responsibility to make sure that 2 projects don't use the same key. There is no way for SQ to know if the analyzed project is an update of an existing project or not.

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