-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to obtain git.branch property with SonarQube build #413
Comments
Mhh in all honesty it wouldn't surprise me if this would be related to #287. Just out curiosity could you try |
Let me be very clear from the start: Ok so in summary I think I have finally found two workarounds, and one that is not directly usable and needs adjustments to the plugin. On a high level the workarounds can be summarized as following:
Workaround 1The sonar-scanner-maven extract's its properties from System.getenv() and happens to also to respect the magic environment variable SONARQUBE_SCANNER_PARAMS.
Workaround 2For this workaround we essentially generate the 'right' 'sonar.projectVersion' with an third party plugin. And because I couldn't get this approach to work with the <!-- make sure the git-commit-id-plugin generates a file via generateGitPropertiesFilename -->
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>
<configuration>
<prefix>git</prefix>
<verbose>true</verbose>
<skipPoms>false</skipPoms>
<!-- <runOnlyOnce>true</runOnlyOnce> -->
<dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
<injectAllReactorProjects>true</injectAllReactorProjects>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<evaluateOnCommit>HEAD</evaluateOnCommit>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<replacementProperties>
<replacementProperty>
<property>sonar.projectVersion</property>
<token>^.*$</token>
<value>${project.version}-${git.branch}</value>
<regex>false</regex>
</replacementProperty>
</replacementProperties>
</configuration>
</plugin>
<!-- now read the generated git file and create the sonar.projectVersion property -->
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>set-custom-property</id>
<phase>compile</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>Properties gitProperties = new Properties()
new File('${project.build.outputDirectory}/git.properties').withInputStream {
gitProperties.load(it)
}
project.properties.setProperty('sonar.projectVersion', "${project.version}-" + gitProperties.getProperty("git.branch"))</source>
</configuration>
</execution>
</executions>
</plugin> Workaround 3 (Needs adjustment to the plugin)For this approach I had in mind to simply use the replacementProperties to set <plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>${git-commit-id-version}</version>
<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
<execution>
<id>validate-the-git-infos</id>
<goals>
<goal>validateRevision</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<prefix>git</prefix>
<verbose>true</verbose>
<skipPoms>false</skipPoms>
<!-- <runOnlyOnce>true</runOnlyOnce> -->
<dotGitDirectory>${project.basedir}/../.git</dotGitDirectory>
<injectAllReactorProjects>true</injectAllReactorProjects>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<evaluateOnCommit>HEAD</evaluateOnCommit>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<replacementProperties>
<replacementProperty>
<property>sonar.projectVersion</property>
<token>^.*$</token>
<value>${project.version}-${git.branch}</value>
<regex>false</regex>
</replacementProperty>
</replacementProperties>
</configuration>
</plugin> maybe something even simpler would be possible. Like a new setting TLDRThank you for reminding me why i stopped using maven :-) Hope this helps and sorry for the nastiness that is involved here - it seems i con't do anything about it. In case I ever need this again: https://docs.docker.com/samples/library/sonarqube/ |
Thank you for your very detailed asnwer. I did not understood the whole of it (I do not know this side of Maven), but it is clear which is the problem and possible workarounds. I do not know if you get a notification but I can see that there is another reply from Maven issue. |
Thanks for the alert - and no I don't get e-Mail notifications from Maven issues. In summary I'd claim we have slightly distinct issues - let me summarize how I understand those two issues: Execute Plugin with it's Plugin's Prefix and pass variable through the direct config (#287)For #287 we essentially use the plugin configuration to pass dynamic properties and use maven's prefix resolution.
and want to run it with it's plugin prefix (aka. If a user wants to tell the plugin about the updated value you either need to integrate the plugin in a normal life-cycle ( Execute Plugin with it's Plugin's Prefix and pass variable through session / project properties (#413)This is somewhat close to the alternative that is suggested in the maven issue. Since the configuration is initialized statically we could pass variables as System environment variables if the plugin supports such behaviour. The second workaround is what I assume a similar issue to This is also essentially the idea for the third workaround that leverages that the sonar plugin also checks the project properties on a project level. Essentially I want to use the functionality of the TLDRI hope this makes sense and gives a better insight on what is going on. For this issue I have hope that I could simplify the problem slightly for you, however for the #287 issue as commented in the maven issue it is not expected that this will change at any time (I feel I just go ahead and close the issues as Outstanding work for this pluginMake it possible to set or overwrite external properties with |
I have removed the 3.0 milestone again, since the outstanding work (e.g. Make it possible to set or overwrite external properties with replacementProperties) is more complicated to achieve the desired behaviour. Essentially the suggested configuration
results in the fact that during initialization the of the plugin the What would be needed here is that the plugin also attempts to resolve the variables correctly. Memo for myself (and how to to it properly): See this for possible inspiration. == EDIT:
|
In case we need the mojoExecution
|
…allow replacements with values that contain unresolved variables (maven sometimes just behaves weird)
#413: use maven's PluginParameterExpressionEvaluator to allow replacements with values that contain variables
As per my latest comment I implemented the reaming parts what can be done from the aspect of this plugin. Essentially you can do now also use:
|
Thank you for fixing this! Encountered this exact issue, and this fix appears to be the nicest of the workarounds. When might this release to Central? |
Hi, Could you perhaps try if the latest snapshot Snapshots are available via:
|
@TheSnoozer I confirm this works as described above, and in a way that fixes the issue for me. I roll forward, I test the feature, it works; I roll back, it stops working. |
Thanks for the confirmation and taking the time to test! I'll try to make a
release asap.
Dominic Jones <[email protected]> schrieb am Do., 21. Nov. 2019,
09:15:
… @TheSnoozer <https://github.com/TheSnoozer> I confirm this works as
described above, and in a way that fixes the issue for me. I roll forward,
I test the feature, it works; I roll back, it stops working.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#413>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABUIG3XRL637NQAFSCCHSOTQUY7SLANCNFSM4HIA26AQ>
.
|
@dominic-jones version 4.0.0 is now released and available via maven-repo: |
Hi,
in my Maven project I have configured SonarQube analysis, and I want to use the name of the current git-branch in the analysis version.
Here is my configuration:
And here is the result
The build is triggered using
mvn clean verify sonar:sonar
I added an
echo
output to make sure the property is correctly created, and there is:But when the sonarqube plugin is triggered (after the echo, so I would expect to have the property value), on SonarQube dashboard I will find the property not resolved.
Here is my current plugin configuration
I enable full log with this command
mvn clean verify sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.verbose=true -X -Dsonar.log.level=DEBUG > R:\log.txt
And found the section related to properties
As far I can see, the property are managed, but the sonar version is not resolved:
Do you know similar cases or possible solutions?
The text was updated successfully, but these errors were encountered: