Alix
Alix

Reputation: 2837

Using the external property feature in SonarQube scanner

Starting from version 2.9 of the SonarQube scanner it is possible to reference variables from within sonar-project.properties:

https://www.sonarsource.com/resources/product-news/2017/03/2017-03-15-sonarqube-scanner-2.9-released.html

To me, the obvious use case of this feature is to avoid having to declare the version of the project twice (once in code and once in sonar-project.properties).

For example, in Swift projects the version is defined in a .plist file as an XML value. Is there an obvious simple method to retrieve this value and reference it in the sonar-project.properties file?

Update: I have managed to get this to work in a TeamCity build (command line build step):

echo "##teamcity[setParameter name='env.APP_VERSION' value='$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "MyApp/Info.plist")']"

and then referencing the variable in sonar-project.properties:

sonar.projectVersion=${env.APP_VERSION}

Upvotes: 0

Views: 728

Answers (1)

Nicolas B.
Nicolas B.

Reputation: 7331

No 'obvious simple method' that I can think of. One approach could be to have a small script picking the version from the .plist and setting it as an environment variable. Environment variable which can then be referenced from sonar-project.properties.

Upvotes: 2

Related Questions