Note: Sonar-runner (mentioned in the original post) is deprecated and replaced with SonarQube Scanner.
This is a working recipe for an iOS (Swift) project with TeamCity (version 2017.1.4) and SonarQube scanner (version 2.9.0.670). I'm adding it here as a future reference to myself and in case someone else needs it:
sonar-project.properties
- Add line:
sonar.projectVersion=${env.APP_VERSION}-SNAPSHOT
TeamCity Build Config, "Parameters"
- Define an environment variable called:
APP_VERSION
+ add other parameters such as sonar.host.url
to avoid coupling source code with the instance version, passwords, etc.
TeamCity Build Config, Build step 1 (Command line)
- Add script (be sure to replace
$MY_APP_FOLDER$
with the real name of the folder:
echo "##teamcity[setParameter name='env.APP_VERSION' value='$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$MY_APP_FOLDER$/Info.plist")']"
TeamCity Build Config, Build step 2 (Command line)
- Add script (assuming develop is the branch that is reported to SonarQube):
if [ %teamcity.build.branch% = "develop" ]
then
SONAR_RUNNER_OPTS=-Xmx1024m sonar-scanner -e \
-Dsonar.host.url=%system.sonar.host.url%\
-Dsonar.login=%system.sonar.login%\
-Dsonar.password=%system.sonar.password%\
-Dsonar.cfamily.build-wrapper-output.bypass=true
fi