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.
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!