Automation, Sytem Engineer

Integrate Sonarqube and Jenkins

Good day, everyone!

Well, today i’m going to help you integrating your sonarqube and jenkins. If you haven’t installed Sonarqube yet, you may check this link to help you first.

So next, to integrate Sonarqube with Jenkins, we need to install 2 Jenkins plugins they are Sonarqube Plugin and Quality Gates Plugin. Install those plugins via Manage Plugin page on your Jenkins.

After install the plugins, go to Jenkins Configure System page and check the Sonarqube server configurations, you can look at mine down below:

And Quality Gates configuration:

Then, open Jenkins global tool configuration page and look for Jenkins Scanner then add Jenkins scanner:

After all, let’s try to create a Jenkins Job.

On the build section, add Execute Sonarqube Scanner like below:

And on the Post-build Action add Quality Gates like below:

After that, save and try to run your Jenkins Job.

How to prove the Quality Gates?

So, to prove that our quality gates is working, let’s create a new quality gates on our Sonarqube. Here I have 2 quality gates in my Sonarqube. They are Sonarqube Way and Quality Gates Test:

On the first test to run Jenkins Job, we will use the Sonarqube Way quality gates. My project is passed the quality gates as below:

PostBuild-Step: Quality Gates plugin build passed: TRUE
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Triggering a new build of new_job_2
Finished: SUCCESS

Next, let’s try to change the quality gates for our project on Sonarqube.

Then, try to run Jenkins job again. We will see a failure notice like below:

PostBuild-Step: Quality Gates plugin build passed: FALSE
Build step 'Quality Gates' marked build as failure
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE

We can see, on the first run Quality Gates plugin build passed is TRUE and it is triggering a new build for new_job_2, while the second try Quality Gates plugin build passed is FALSE and marked build as failure and it will not triggering any job. PS: You need to add build trigger section on the job configuration setup so if a build is success it will trigger a job to run/build.

So, that’s all for today! 🙂

Please comment for any suggestion/question!

Thank you!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s