Hello,
I am attempting to use powershell rather than bat for withSonarQubeEnv() in a Declarative Pipeline for Jenkins.
NOTE: I use the command line for an Angular Project to be submitted with Typescript files (and the corresponding linting file, which is not included in the below scripts yet). I prefer not having a properties file since all the applications will be set up similar and I would like to make the below a global library eventually.
stage('SonarQube') {
steps {
withSonarQubeEnv('SonarQube Corp Server') {
sonar-scanner -Dsonar.login=$env:SONAR_AUTH_TOKEN -Dsonar.host.url=$env:SONAR_HOST_URL `
-Dsonar.projectKey="NAWM_$env:PROJECT_NAME" -Dsonar.projectName="NAWM_$env:PROJECT_NAME" -Dsonar.projectVersion=$env:ComponentVersion `
-Dsonar.projectBaseDir=$env:WORKSPACE -Dsonar.home=$env:WORKSPACE `
-Dsonar.sourceEncoding=UTF-8 `
-Dsonar.exclusions="**\\node_modules\\**,**\\dist\\**,**\\src\\**\\*.spec.ts,**\\app\\swagger\\**" `
-Dsonar.sources=src\\ -Dsonar.verbose=true
sonar-scanner -Dsonar.login=%SONAR_AUTH_TOKEN% -Dsonar.host.url=%SONAR_HOST_URL% ^
-Dsonar.projectKey="NAWM_%%PROJECT_NAME%" -Dsonar.projectName="NAWM_%PROJECT_NAME%" -Dsonar.projectVersion=%ComponentVersion% ^
-Dsonar.projectBaseDir=%WORKSPACE% -Dsonar.home=%WORKSPACE% ^
-Dsonar.sourceEncoding=UTF-8 ^
-Dsonar.exclusions="**\\node_modules\\**,**\\dist\\**,**\\src\\**\\*.spec.ts,**\\app\\swagger\\**" ^
-Dsonar.sources=src\\ -Dsonar.verbose=true
What is interesting is the powershell version of the script has errors with reading in the first parameter of the function vs the bat file (which executes). I get this regardless of the first option I use. The error for the powershell version is as follows :
[SonarQube] Injecting SonarQube environment variables using the configuration: SonarQube Corp Server
[Pipeline] [SonarQube] {
[Pipeline] [SonarQube] powershell
[SonarQube] [TradeCalc_CDA_Jenkinsfile-4HEAPVKV77ZQKL5FQ27QFBSLPAXPYSZDVQTW2RG5FTR7NLKQBDCQ] Running PowerShell script
[SonarQube] sonar-scanner : ERROR: Unrecognized option: .login=******
[SonarQube] At C:\Jenkins\workspace\TradeCalc_CDA_Jenkinsfile-4HEAPVKV77ZQKL5FQ27QFBSLPAXPYSZDVQTW2RG5FTR7NLKQBDCQ@tmp\durable-c69b
[SonarQube] 0d43\powershellScript.ps1:2 char:33
[SonarQube] + ... sonar-scanner -Dsonar.login=$env:SONAR_AUTH_TOKEN -Dsonar ...
[SonarQube] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[SonarQube] + CategoryInfo : NotSpecified: (ERROR: Unrecogn...5f38c3c62dddd6f:String) [], RemoteException
[SonarQube] + FullyQualifiedErrorId : NativeCommandError
[SonarQube]
[SonarQube] INFO:
[SonarQube] INFO: usage: sonar-scanner [options]
[SonarQube] INFO:
[SonarQube] INFO: Options:
[SonarQube] INFO: -D,--define <arg> Define property
[SonarQube] INFO: -h,--help Display help information
[SonarQube] INFO: -v,--version Display version information
[SonarQube] INFO: -X,--debug Produce execution debug output
Thoughts on why this might be? I didn't know if this would be a SonarQube plugin issue or the powershell maintainers for Jenkins. I thought I would try here first in case I am missing something obvious.
Thanks!