There are various ways to do this. Using bamboo is a very nice way of running ant scripts like this, but you can also run the jobs manually or using a cron job.
You should analyse and modify the antbuild.xml file to your needs. The default jobs are listed below and must be run from a project folder containing a sonar-project.properties file to specify the projects Name and Key. An example of the sonar-project.properties file and the default antbuild.xml are available with the plugin download. The path "../antbuild.xml" in the examples below always refers to the actual path of your antbuild.xml file and should be changed as needed.
ant -f ../antbuild.xml deletesrc
deletes all the LOCAL source code (so that you will detect any source code changes)
ant -f ../antbuild.xml download
downloads all the source code from the Salesforce server
ant -f ../antbuild.xml commit
commits to your scm using the ‘last modified date’ meta data from Salesforce.
ant -f ../antbuild.xml commitall
commits any uncommited code (because of missing metadata, etc) using a standard user and message
ant -f ../antbuild.xml sonar
run the actual SonarQube analysis job.
ant -f ../antbuild.xml analyse
runs a combination of the above. By default we specify: ‘deletesrc, download, sonar’