Uploading a sonar Quality profile (.xml) programmatically and set it as default - ruby

I am using chef and one of my recipe needs to upload the sonar quality profile automatically and set it as default. Right now, I am doing it using browser automation using selenium but I dont like it and i dont believe that it is the right way to do. Has anyone done the upload using some API or a script? Any programming language or specific methods is fine although I am using Ruby (chef is a ruby DSL). Any pointers please?

SonarQube supports a REST API that you could invoke using ruby.
There is a documentation option for:
Restore a quality profile
Setting profile as default
I have never tried these, so I think you'll have to take a look at how Sonar performs profile backups. I would suggest considering an approach where the profile is saved in your cookbook as a template (allowing you to sub values in) and submitted to Sonar as a restoration.

Related

Analyze SCSS with SonarQube on TeamCity

I am using SONAR-CSS-PLUGIN to check all SCSS file in my repository.
As it comes with default set of 100+ rules, at this moment am not willing to apply all rules in one go as as there is legacy code too and it's reporting many errors.
I would like to incremental by applying a set of rules (lets say 10) everyweek.
I am using TeamCity as build tool.
Here is my TeamCity configuration.
-Dsonar.language=scss
-Dsonar.inclusions=Src/**/*.scss
-Dsonar.css.configPath= wanna give path to .stylelintrc or custom set of rules
-Dsonar.sourceEncoding=UTF-8
%sonar.github.pullRequest%
%sonar.github.repository%
I can not find any documentaion showing how to configure above plugin in TeamCity.
Is this -Dsonar.css.configPath right property??
No matter what path I provide -Dsonar.css.configPath= SomePath It always applies all the rules bydefault.
I would like to apply only some rules for time being.
(For people who may need it in future)
Well, I asked question on their git-hub repository.
Good to know they are responsive.
And the creator says its not possible to point any .stylelintrc at this moment.
Also to apply a set of rules one need to create new Quality Profile and set that as default for respective repository in sonar web interface.
Note: Above option is available only for Administrator access.
See detailed thread HERE

Integrate Jenkins trend chart into dashing dashboard

We are running a Jenkins instance with various test jobs as part of the build chain.
I would like to integrate the build, test trend and general CI status information into graphs/widgets using the Shopify Dashing dashboard http://shopify.github.io/dashing/.
In other words, to have a standalone dashboard that indicates key info from the Jenkins instance.
Does anyone have experience with doing this kind of thing? Can you point me in the direction of any good resources/tutorials etc?
Many thanks
Jenkins' url structure is pretty rigid. For example, the build time trend graph for a project would be available at:
http://<jenkinshost>:<port>/job/<jobname>/buildTimeGraph/png
etc. You should be able to just statically link to these using tags in your HTML / ERB / templating language of your choice.
Other information is available via the remote access rest api, for e.g.
http://<jenkinshost>:<port>/job/<jobname>/lastSuccessfulBuild/api/json?pretty=true
would give you a structure containing a lot of project metadata
Have a look at the documentation on the remote access API: https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

Per-test sample data generation for load testing?

I have a set of load tests, each testing a specific section of Sharepoint site. How can I automate the generation of sample data prior to each test?
I know that load tests allow me to specify tests that are run before/after a specific virtual user's test mix, but those are meant for user-specific setup like logging on. I want to create sample data for all users.
I can put my setup code into the Team Build template, but that doesn't take into account whether the test using the sample data is in the test list being run or not. If I modify the test list, I would also need to modify the build template as well. I cannot put the setup code into a test that is run before the load test either, because load tests must be run with the .Net 4.0 framework while accessing Sharepoint's API requires 3.5.
I could rewrite my sample data generation logic with Powershell and start it from a .Net 4.0 unit test. Is it my best option or is there a more elegant way?
I think you question is more TeamBuild related than SharePoint. For short, the best way how to setup (and teardown) testdata in SharePoint is using PoSh in conjunction with the Microsoft.PowerShell.SharePoint SnapIn.
You can start your PowerShell scripts from Everywhere in TeamBuild. That's actually how I extend the default TeamBuild template. I've create a single custom build template, this template contains numerous PoSh hooks. While setting up a new project you can easily hook your scripts everywhere you need.
To be really independent from any .NET FX version you could create your sampledata using REST DataServices (ListData.svc)

A good strategy for knowing the versions of deployed applications?

In order to know which revision number the application is built from, we use to give the ears we deploy to Glassfish names like myapp_2012-01-20_rev22123.ear. Then we can simply login to Glassfish and see what version is deployed in the web interface (as the appname is the name of the ear file). A downside of this approach is that we need to do a manual undeploy/redeploy to update the name...
But I would like to script the undeploy/deploy process, and having each version of an ear get a different name is not very suitable to scripting this redeployment process. Glassfish 2 does not support the "list applications" goal that Glassfish 3 has, which I could have used to retrieve the application name to undeploy.
So is there any good strategy that will easily allow us to see what version is deployed of an application, and that does not suffer from the above fault?
It would be preferable if this meant we did not have to change the existing applications (like add a jsp page or something to show the current scm revision), but a change in a Maven build script would be acceptable.
I faced a similar issue, I finally came around it by using maven-buildnumber-plugin and writing a simple servlet to get build information. You can find the details in the blog post I made.
Why not use the built-in GlassFish Server versioning to assign a version number at deploy time? This will also enable you to rollback to prior versions. For example:
asadmin deploy --name MyApplication:2012-01-20_rev22123 MyApplication.ear
There is more information on application versioning here:
http://docs.oracle.com/cd/E18930_01/html/821-2417/gihzx.html#gkhhv
Hope this helps.

Create new user in sonar

Is it possible to create a new user in sonar without using the web interface?
I need to write a script that inserts the same users for some tools, including sonar.
There are three ways you can do this:
Write directly to the database (there is a simple table called users).
Use the LDAP plugin, if you specify sonar.authenticator.createUsers: true in sonar.properties, it will create the users in the sonar database automatically the first time they authenticate.
Write a java application that depends on the sonar plugin API, you can then use constructor injection to get a Sonar hibernate session and persist the user you want. See Here.
Since SonarQube version 3.6, there is support for user management in webservice API:
https://sonarqube.com/web_api/api/users
http://docs.sonarqube.org/display/DEV/Web+API
The web service API does not seem to support user management. Anything's possible, but it doesn't look like this is offered directly via Sonar.
You could probably use some web automation library (webbrowser, webunit, watir, twill) to do it through the running server; it might even be possible to just use something like 'curl' by looking carefully at the page source for the users/create form.
Or, if you want to go straight to the database, you could try to pull out the user creation functionality from the code and mess with the sonar.users table directly.
There is the LDAP Plugin, which would take care of authentication, but it still requires you to create the users in Sonar, so that wouldn't solve your problem.

Resources