JetBrains / TeamCity.SonarQubePlugin

A plugin for TeamCity server allowing you to configure and run SonarQube analysis from the CI
Apache License 2.0
53 stars 32 forks source link

Expose SonarQube server URL as a build parameter #70

Open ogerovich opened 4 years ago

ogerovich commented 4 years ago

There is already %runParam.sonarServer%, but it's some kind of unique identifier. Please provide something like %runParam.sonarServerUrl%. This way I could pass it as a parameter within a build step to my custom script.

Linfar commented 4 years ago

Yes, sonarServer is UUID of a connection used in a certain build step. When build is started a number of additional parameters are resolved basing on this UUID, including sonar.host.url with the URL. However due to current implementation these parameters are set only for starting build and cannot be accessed on server side.

Could you please describe how do you get access to runner parameters - where runParam prefix comes from?

ogerovich commented 4 years ago

When I was testing my script earlier, I was using SonarQube plugin 2017.1-28. I used a Python build step. I started typing %sonar in command line arguments text box, and a few matches appeared. %runParam.sonarServer% was among them. When I tried to run the build, I discovered that it's the UUID. I have since updated SonarQube plugin to version 2017.1-30, and auto-complete no longer shows any matches for %sonar. Was this disabled between 2017.1-28 and 2017.1-30?

It does not matter to me how the parameter is exposed as long as I can use it either in a build step or to define another build parameter. Ideally, auto-complete works, but this is not a requirement.

Linfar commented 4 years ago

%runParam.sonarServer% isn't a parameter provided by SonarQube plugin (and has never been). AFAIK default TeamCity functionality doesn't provide runParam. prefix neither. Moreover runner parameters can exist only during executing step where these parameters are defined and mean nothing in other steps.

So I cannot easily provide such parameter from the plugin - eg there can be 2 different Sonar Runner usages with different servers during one build.

MSBuild Scanner seems to be easier here since usually there is only one simultaneous Start task (there can be subsequent 2 start-finish tasks during the build but I really doubt anyone will ever intersect them) and server is used in the Start task. So probably I can set parameter value between start and finish.

I'll try to find some way to provide SonarQube server urls. If you can describe how you'll use such parameter it could help me.

ogerovich commented 4 years ago

I'm now unsure about how I discovered runParam. I thought it was auto-complete, but, if it was never provided, maybe I just looked at a completed build and found it on Parameters tab.

I need the URL for SonarQube Runner and SonarScanner for MSBuild. After those build steps, I have a command-line step that calls a script, which accepts %PARAMS% build parameter. PARAMS is defined on Parameters tab as a string, which contains the hard-coded Sonar URL like this ... /set SERVER_URL=http://myserver:900 .... I'd like to have some reference, ideally with auto-complete, so I could do something like this: ... /set SERVER_URL=%SONAR_URL% ....