简体   繁体   中英

Run Sonar Runner on each SVN commit to analyse outgoing SVN files

I've installed SonarQube on my Ubuntu machine and ran a sonar runner for one of my PHP projects. It works perfectly and I can see all the errors in the sonar web panel.

http://localhost:9000/sonar

But what I really want is to analyze all the files for errors which are going to be committed in my svn repository. I read a lot about Hudson and Jenkins but really not getting the exact idea to do it. In my previous company there was both sonar and svn. When we committed the files in svn, sonar used to analyze the codes of all outgoing files and my svn client returned all the error.

I also read about pre and post commit svn hooks but experts are saying that it would take a lot of time to commit the file and will let the other users wait for their svn usage.

Assuming you have access to svn repository server, an automated build system(maven/ant or similar) and sonar server has a build breaker plugin with quality gates configured, you can write a simple shell script to :

  • svn update repository workspace
  • compile task(maven/ant)
  • execute sonar-runner in incremental mode
  • custom error messages in case build breaks

Copy the script to the repository hook directory. If the repository already has a pre-commit hook, append the command /bin/sh your_shell_script_full_path .

If the pre-commit hook file does not exist, create the file pre-commit.sh and include the same.

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