SonnarQube scanner for Jenkins plugin - 2.8.1
I have a Jenkins job that is failing when executing the SonarQube Scanner build step.
Console output below:
Any ideas why?
[Core-SonarQube] $ /home/build/tools/hudson.plugins.sonar.SonarRunnerInstallation/IL_Sonarqube/bin/sonar-scanner -Dsonar.host.url=http://sonarqube-dev.xxxxxx.com -Dsonar.projectName=Cix_Core -Dsonar.projectVersion=5.11 -Dsonar.projectKey=com.cix:core:5.7 -Dsonar.java.binaries=classes -Dsonar.sources=. -Dsonar.projectBaseDir=/home/build/workspace/SonarQube/Core-SonarQube
/home/build/tools/hudson.plugins.sonar.SonarRunnerInstallation/IL_Sonarqube/bin/sonar-scanner: syntax error at line 16: `target=$' unexpected
There’s nothing obvious in the analysis command line you supplied to explain the error your’e getting. Could you share a little more detail about how analysis is configured in your Jenkins job?
I was able to resolve the issue by running the scan on a different Jenkins agent.
I got the same issue and found out that the script sonar-scanner (version 126.96.36.1992 and 188.8.131.520 in my case) on linux doesn’t use the right shell interpreter or sub-command syntax.
The default shell used is sh.
Inside the script some variables has assigned values based on subcommand and the syntax used is : var=$(some command).
But this syntax is bash based. The equivalent in sh is var=`some command`.
To correct this the script must use:
- bash interpreter
- `` sub-command syntax
Welcome to the community and congrats on such a valuable first post!
I’m following up on this internally.
Aaaand here’s the ticket: SQSCANNER-78
I tried a few older systems but could not find one where
/bin/sh did not support the
/bin/sh is usually a symlink to
dash, which all seem to support this syntax.
Can you please tell me where I can find such
$(...) is a problem?
I’m inclined to fix this by changing the
`...` syntax, but then I also need a way to test that the rest of the script doesn’t use some other features that are not supported in this shell.
Well, you may encounter the issue on solaris (in my case solaris 10) and any other OS where sh is not a symlink to any “modern” shell.
Technically, both syntax do the same and are POSIX. As far as I know.
$() is better when dealing with nested subcommands.
If you don’t want to change the syntax, you can change the shebang and point to
/usr/bin/bash. But bash location will depend on the OS. Therefore you’ll have to build a script for every variations.