2
votes

I have a number of projects that need to be analysed by SONAR from jenkins. These projects include ant and maven projects. I have created a separate job for each SONAR analysis in jenkins.

Is it possible to have a single jenkins job in which I can pass some parameters from each individual sonar job and then see the dashboard?

If so, how do i go about it?

2

2 Answers

1
votes

This solution is for Subversion and Maven.

  1. Install the Parameterized Trigger Plugin
  2. Create a Maven job for the SonarQube analysis, eg. _common-sonar with these settings:
    • Source Code Management: "Subversion", Repository URL: $PREVIOUS_SVN_URL, Check-out Strategy: "Always check out a fresh copy"
    • Build: Goals and options: install
    • Post-build Actions: "Sonar"
  3. For the job you want to run analysis on add a Post-build Action "Trigger parameterized build on other projects" with these settings:
    • Projects to build: _common-sonar
    • Add Predefined parameters: Parameters: PREVIOUS_SVN_URL=${SVN_URL}

Now when the job-to-analyse completes it triggers the analysis job. The analysis job checks out the same SVN URL which was used by the first job.

This solution works without scripting or copying workspaces but there are quite obvious limitations and non-ideal features:

  • the build command is always only mvn install
  • the SVN checkout may be from different revision than original build
  • checkout and build are always done from scratch
  • I didn't consider ant at all here.

Improvement ideas are quite welcome!

Late improvement edit:

Instead of using a maven build ( in _common-sonar), you may also use SonarQube directly by invoking a Standalone SonarQube analysis

Additionally to the SVN URL you can add a parameter for the build tag and project name to use in sonar. Simply add

  • NAME=YOUR_PROJECT_NAME
  • BUILDTAG=$BUILD_TAG

beneath the PREVIOUS_SVN_URL parameter.

In your _common-sonar you can use it with ${NAME} and ${BUILDTAG}.

0
votes

In a similar need I had once, I created a single job, which pulled sources of several projects (each to its own sub-folder in job's workspace).
Then, I wrote a simple shell script that looped over all directories and ran the sonar analysis.
The job had the sonar post build plugin which showed an aggregated report.
Unfortunately, I don't have an example as this was some years ago, but you can make it work.

I hope this helps.