| | | |
Offset 695, 15 lines modified | Offset 695, 15 lines modified |
695 | ················path:·"analysis/scan/sonarscanner-for-jenkins", | 695 | ················path:·"analysis/scan/sonarscanner-for-jenkins", |
696 | ················content:·"---\ntitle:·SonarScanner·for·Jenkins\nurl:·/analysis/scan/sonarscanner-for-jenkins/\n---\n\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey=\"scannerjenkins\"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner-jenkins.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\nThis·plugin·lets·you·centralize·the·configuration·of·SonarQube·server·connection·details·in·Jenkins·global·configuration.\n\nThen·you·can·trigger·SonarQube·analysis·from·Jenkins·using·standard·Jenkins·Build·Steps·or·[Jenkins·Pipeline·DSL](https://jenkins.io/solutions/pipeline/)·to·trigger·analysis·with:\n\n*·[SonarScanner](/analysis/scan/sonarscanner/)\n*·[SonarScanner·for·Maven](/analysis/scan/sonarscanner-for-maven/)\n*·[SonarScanner·for·Gradle](/analysis/scan/sonarscanner-for-gradle/)\n*·[SonarScanner·for·.NET](/analysis/scan/sonarscanner-for-msbuild/)\n\nOnce·the·job·is·complete,·the·plugin·will·detect·that·a·SonarQube·analysis·was·made·during·the·build·and·display·a·badge·and·a·widget·on·the·job·page·with·a·link·to·the·SonarQube·dashboard·as·well·as·quality·gate·status.\n\n##·Installation\n1.·[Install·the·SonarScanner·for·Jenkins·via·the·Jenkins·Update·Center](https://plugins.jenkins.io/sonar).\n1.·Configure·your·SonarQube·server(s):\n···1.·Log·into·Jenkins·as·an·administrator·and·go·to·**Manage·Jenkins·>·Configure·System**.\n···1.·Scroll·down·to·the·SonarQube·configuration·section,·click·**Add·SonarQube**,·and·add·the·values·you're·prompted·for.\n···1.·The·server·[authentication·token](/user-guide/user-token/)·should·be·created·as·a·'Secret·Text'·credential.\n\n##·Analyzing·a·.NET·solution\n**Global·Configuration**··\nThis·step·is·mandatory·if·you·want·to·trigger·any·of·your·analyses·with·the·SonarScanner·for·.NET.·You·can·define·as·many·scanner·instances·as·you·wish.·Then·for·each·Jenkins·job,·you·will·be·able·to·choose·which·launcher·to·use·to·run·the·SonarQube·analysis.\n1.·Log·into·Jenkins·as·an·administrator·and·go·to·**Manage·Jenkins·>·Global·Tool·Configuration**\n1.·Click·on·**Add·SonarScanner·for·MSBuild**\n1.·Add·an·installation·of·the·latest·available·version.·Check·**Install·automatically**·to·have·the·SonarScanner·for·MSBuild·automatically·provisioned·on·your·Jenkins·executors\n\nIf·you·do·not·see·any·available·version·under·Install·from·GitHub,·first·go·to·Manage·Jenkins·>·Manage·Plugins·>·Advanced·and·click·on·Check·now\n\n**Job·Configuration**··\n1.·Configure·the·project,·and·go·to·the·**Build**·section.\n1.·Add·the·SonarQube·for·MSBuild·-·Begin·Analysis·to·your·build\n1.·Configure·the·SonarQube·Project·Key,·Name,·and·Version·in·the·SonarScanner·for·MSBuild·-·Begin·Analysis·build·step\n1.·Add·the·MSBuild·build·step·or·the·Execute·Windows·batch·command·to·execute·the·build·with·MSBuild·14·(see·compatibility)·to·your·build.\n1.·Add·the·SonarQube·for·MSBuild·-·End·Analysis·build·steps·to·your·build\n\n##·Analyzing·a·Java·project·with·Maven·or·Gradle\n**Global·Configuration**··\n1.·Log·into·Jenkins·as·an·administrator·and·go·to·Manage·Jenkins·>·Configure·System\n1.·Scroll·to·the·SonarQube·servers·section·and·check·Enable·injection·of·SonarQube·server·configuration·as·build·environment·variables\n\n**Job·Configuration**··\n1.·**Configure**·the·project,·and·go·to·the·**Build·Environment**·section.\n1.·Enable·**Prepare·SonarScanner·environment**·to·allow·the·injection·of·SonarQube·server·values·into·this·particular·job.·If·multiple·SonarQube·instances·are·configured,·you·will·be·able·to·choose·which·one·to·use.\nOnce·the·environment·variables·are·available,·use·them·in·a·standard·Maven·build·step·(Invoke·top-level·Maven·targets)·by·setting·the·Goals·to·include,·or·a·standard·Gradle·build·step·(Invoke·Gradle·script)·by·setting·the·Tasks·to·execute.\n\nMaven·goal:\n```\n$SONAR_MAVEN_GOAL\n```\nGradle·task:\n```\nsonarqube\n```\n\nIn·both·cases,·launching·your·analysis·may·require·authentication.·In·that·case,·make·sure·that·the·Global·Configuration·defines·a·valid·SonarQube·token.\n\n##·Analyzing·other·project·types\n\n**Global·Configuration**··\nThis·step·is·mandatory·if·you·want·to·trigger·any·of·your·SonarQube·analyses·with·the·SonarScanner.·You·can·define·as·many·scanner·instances·as·you·wish.·Then·for·each·Jenkins·job,·you·will·be·able·to·choose·which·launcher·to·use·to·run·the·SonarQube·analysis.\n\n1.·Log·into·Jenkins·as·an·administrator·and·go·to·**Manage·Jenkins·>·Global·Tool·Configuration**\n1.·Scroll·down·to·the·SonarScanner·configuration·section·and·click·on·Add·SonarScanner.·It·is·based·on·the·typical·Jenkins·tool·auto-installation.·You·can·either·choose·to·point·to·an·already·installed·version·of·SonarScanner·(uncheck·'Install·automatically')·or·tell·Jenkins·to·grab·the·installer·from·a·remote·location·(check·'Install·automatically')\n\nIf·you·don't·see·a·drop-down·list·with·all·available·SonarScanner·versions·but·instead·see·an·empty·text·field·then·this·is·because·Jenkins·still·hasn't·downloaded·the·required·update·center·file·(default·period·is·1·day).·You·may·force·this·refresh·by·clicking·the·'Check·Now'·button·in·Manage·Plugins·>·Advanced·tab.\n\n**Job·Configuration**··\n1.·**Configure**·the·project,·and·go·to·the·**Build**·section.·\n1.·Add·the·SonarScanner·build·step·to·your·build.\n1.·Configure·the·SonarQube·analysis·properties.·You·can·either·point·to·an·existing·sonar-project.properties·file·or·set·the·analysis·properties·directly·in·the·**Analysis·properties**·field\n\n\n\n##·Using·a·Jenkins·pipeline\nWe·provide·a·`withSonarQubeEnv`·block·that·allows·you·to·select·the·SonarQube·server·you·want·to·interact·with.·Connection·details·you·have·configured·in·Jenkins·global·configuration·will·be·automatically·passed·to·the·scanner.\n\nIf·needed·you·can·override·the·`credentialId`·if·you·don't·want·to·use·the·one·defined·in·global·configuration·(for·example·if·you·define·credentials·at·folder·level).\n\nIf·you·only·need·the·SonarQube·environment·variables·to·be·expanded·in·the·build·context·then·you·can·override·the·`envOnly`·flag.\n```\nwithSonarQubeEnv('My·SonarQube·Server',·envOnly:·true)·{\n··//·This·expands·the·evironment·variables·SONAR_CONFIG_NAME,·SONAR_HOST_URL,·SONAR_AUTH_TOKEN·that·can·be·used·by·any·script.\n··println·${env.SONAR_HOST_URL}·\n}\n```\n\nHere·are·some·examples·for·every·scanner,·assuming·you·run·on·Unix·slaves·and·you·have·configured·a·server·named·\"My·SonarQube·Server\"·as·well·as·required·tools.·If·you·run·on·Windows·slaves,·just·replace·`sh`·with·`bat`.\n\nSonarScanner:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····def·scannerHome·=·tool·'SonarScanner·4.0';\n····withSonarQubeEnv('My·SonarQube·Server')·{·//·If·you·have·configured·more·than·one·global·server·connection,·you·can·specify·its·name\n······sh·\"${scannerHome}/bin/sonar-scanner\"\n····}\n··}\n}\n```\nSonarScanner·for·Gradle:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····withSonarQubeEnv()·{·//·Will·pick·the·global·server·connection·you·have·configured\n······sh·'./gradlew·sonarqube'\n····}\n··}\n}\n```\nSonarScanner·for·Maven:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····withSonarQubeEnv(credentialsId:·'f225455e-ea59-40fa-8af7-08176e86507a',·installationName:·'My·SonarQube·Server')·{·//·You·can·override·the·credential·to·be·used\n······sh·'mvn·org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar'\n····}\n··}\n}\n```\nSonarScanner·for·.NET:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('Build·+·SonarQube·analysis')·{\n····def·sqScannerMsBuildHome·=·tool·'Scanner·for·MSBuild·4.6'\n····withSonarQubeEnv('My·SonarQube·Server')·{\n······bat·\"${sqScannerMsBuildHome}\\\\SonarQube.Scanner.MSBuild.exe·begin·/k:myKey\"\n······bat·'MSBuild.exe·/t:Rebuild'\n······bat·\"${sqScannerMsBuildHome}\\\\SonarQube.Scanner.MSBuild.exe·end\"\n····}\n··}\n}\n```\n\n##·Pause·pipeline·until·the·Quality·Gate·is·computed\nThe·`waitForQualityGate`·step·will·pause·the·pipeline·until·SonarQube·analysis·is·completed·and·returns·Quality·Gate·status.\n\n###·Pre-requisites:\n*·Configure·a·webhook·in·your·SonarQube·server·pointing·to·`<your·Jenkins·instance>/sonarqube-webhook/`·\n*·Use·`withSonarQubeEnv`·step·in·your·pipeline·(so·that·SonarQube·taskId·is·correctly·attached·to·the·pipeline·context).\n\n\nScripted·pipeline·example:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····withSonarQubeEnv('My·SonarQube·Server')·{\n······sh·'mvn·clean·package·sonar:sonar'\n····}·//·submitted·SonarQube·taskId·is·automatically·attached·to·the·pipeline·context\n··}\n}\n··\n//·No·need·to·occupy·a·node\nstage(\"Quality·Gate\"){\n··timeout(time:·1,·unit:·'HOURS')·{·//·Just·in·case·something·goes·wrong,·pipeline·will·be·killed·after·a·timeout\n····def·qg·=·waitForQualityGate()·//·Reuse·taskId·previously·collected·by·withSonarQubeEnv\n····if·(qg.status·!=·'OK')·{\n······error·\"Pipeline·aborted·due·to·quality·gate·failure:·${qg.status}\"\n····}\n··}\n}\n```\nThanks·to·the·webhook,·the·step·is·implemented·in·a·very·lightweight·way:·no·need·to·occupy·a·node·doing·polling,·and·it·doesn't·prevent·Jenkins·to·restart·(step·will·be·restored·after·restart).·Note·that·to·prevent·race·conditions,·when·the·step·starts·(or·is·restarted)·a·direct·call·is·made·to·the·server·to·check·if·the·task·is·already·completed.\n\nDeclarative·pipeline·example:\n```\npipeline·{\n····agent·any\n····stages·{\n········stage('SCM')·{\n············steps·{\n················git·url:·'https://github.com/foo/bar.git'\n············}\n········}\n········stage('build·&&·SonarQube·analysis')·{\n············steps·{\n················withSonarQubeEnv('My·SonarQube·Server')·{\n····················//·Optionally·use·a·Maven·environment·you've·configured·already\n····················withMaven(maven:'Maven·3.5')·{\n························sh·'mvn·clean·package·sonar:sonar'\n····················}\n················}\n············}\n········}\n········stage(\"Quality·Gate\")·{\n············steps·{\n················timeout(time:·1,·unit:·'HOURS')·{\n····················//·Parameter·indicates·whether·to·set·pipeline·to·UNSTABLE·if·Quality·Gate·fails\n····················//·true·=·set·pipeline·to·UNSTABLE,·false·=·don't\n····················waitForQualityGate·abortPipeline:·true\n················}\n············}\n········}\n····}\n}\n```\n\nIf·you·want·to·run·multiple·analysis·in·the·same·pipeline·and·use·waitForQualityGate·you·have·to·do·everything·in·order:\n```\npipeline·{\n····agent·any\n····stages·{\n········stage('SonarQube·analysis·1')·{\n············steps·{\n················sh·'mvn·clean·package·sonar:sonar'\n············}\n········}\n········stage(\"Quality·Gate·1\")·{\n············steps·{\n················waitForQualityGate·abortPipeline:·true\n············}\n········}\n········stage('SonarQube·analysis·2')·{\n············steps·{\n················sh·'gradle·sonarqube'\n············}\n········}\n········stage(\"Quality·Gate·2\")·{\n············steps·{\n················waitForQualityGate·abortPipeline:·true\n············}\n········}\n····}\n}\n```\n\n###·Configuring·a·webhook·secret\n\nIf·you·want·to·verify·the·webhook·payload·that·is·sent·to·Jenkins,·you·can·add·a·secret·to·your·webhook·on·SonarQube.\n\nTo·set·the·secret:·\n\n1.·In·Jenkins,·navigate·to·**Manage·Jenkins·>·Configure·System·>·SonarQube·Server·>·Advanced·>·Webhook·Secret**·and·click·the·**Add**·button.\n1.·Select·**Secret·text**·and·give·the·secret·an·ID.\n1.·Select·the·secret·from·the·dropdown·menu.\n\nIf·you·want·to·override·the·webhook·secret·on·a·project·level,·you·can·add·the·secret·to·Jenkins·and·then·reference·the·secret·ID·when·calling·`waitForQualityGate`.\n\n····waitForQualityGate(webhookSecretId:·'yourSecretID')····\nif·your·pipeline·is·declarative·or\n\n····waitForQualityGate·webhookSecretId:·'yourSecretID'\nif·your·pipeline·is·scripted.\n" | 696 | ················content:·"---\ntitle:·SonarScanner·for·Jenkins\nurl:·/analysis/scan/sonarscanner-for-jenkins/\n---\n\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey=\"scannerjenkins\"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner-jenkins.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\nThis·plugin·lets·you·centralize·the·configuration·of·SonarQube·server·connection·details·in·Jenkins·global·configuration.\n\nThen·you·can·trigger·SonarQube·analysis·from·Jenkins·using·standard·Jenkins·Build·Steps·or·[Jenkins·Pipeline·DSL](https://jenkins.io/solutions/pipeline/)·to·trigger·analysis·with:\n\n*·[SonarScanner](/analysis/scan/sonarscanner/)\n*·[SonarScanner·for·Maven](/analysis/scan/sonarscanner-for-maven/)\n*·[SonarScanner·for·Gradle](/analysis/scan/sonarscanner-for-gradle/)\n*·[SonarScanner·for·.NET](/analysis/scan/sonarscanner-for-msbuild/)\n\nOnce·the·job·is·complete,·the·plugin·will·detect·that·a·SonarQube·analysis·was·made·during·the·build·and·display·a·badge·and·a·widget·on·the·job·page·with·a·link·to·the·SonarQube·dashboard·as·well·as·quality·gate·status.\n\n##·Installation\n1.·[Install·the·SonarScanner·for·Jenkins·via·the·Jenkins·Update·Center](https://plugins.jenkins.io/sonar).\n1.·Configure·your·SonarQube·server(s):\n···1.·Log·into·Jenkins·as·an·administrator·and·go·to·**Manage·Jenkins·>·Configure·System**.\n···1.·Scroll·down·to·the·SonarQube·configuration·section,·click·**Add·SonarQube**,·and·add·the·values·you're·prompted·for.\n···1.·The·server·[authentication·token](/user-guide/user-token/)·should·be·created·as·a·'Secret·Text'·credential.\n\n##·Analyzing·a·.NET·solution\n**Global·Configuration**··\nThis·step·is·mandatory·if·you·want·to·trigger·any·of·your·analyses·with·the·SonarScanner·for·.NET.·You·can·define·as·many·scanner·instances·as·you·wish.·Then·for·each·Jenkins·job,·you·will·be·able·to·choose·which·launcher·to·use·to·run·the·SonarQube·analysis.\n1.·Log·into·Jenkins·as·an·administrator·and·go·to·**Manage·Jenkins·>·Global·Tool·Configuration**\n1.·Click·on·**Add·SonarScanner·for·MSBuild**\n1.·Add·an·installation·of·the·latest·available·version.·Check·**Install·automatically**·to·have·the·SonarScanner·for·MSBuild·automatically·provisioned·on·your·Jenkins·executors\n\nIf·you·do·not·see·any·available·version·under·Install·from·GitHub,·first·go·to·Manage·Jenkins·>·Manage·Plugins·>·Advanced·and·click·on·Check·now\n\n**Job·Configuration**··\n1.·Configure·the·project,·and·go·to·the·**Build**·section.\n1.·Add·the·SonarQube·for·MSBuild·-·Begin·Analysis·to·your·build\n1.·Configure·the·SonarQube·Project·Key,·Name,·and·Version·in·the·SonarScanner·for·MSBuild·-·Begin·Analysis·build·step\n1.·Add·the·MSBuild·build·step·or·the·Execute·Windows·batch·command·to·execute·the·build·with·MSBuild·14·(see·compatibility)·to·your·build.\n1.·Add·the·SonarQube·for·MSBuild·-·End·Analysis·build·steps·to·your·build\n\n##·Analyzing·a·Java·project·with·Maven·or·Gradle\n**Global·Configuration**··\n1.·Log·into·Jenkins·as·an·administrator·and·go·to·Manage·Jenkins·>·Configure·System\n1.·Scroll·to·the·SonarQube·servers·section·and·check·Enable·injection·of·SonarQube·server·configuration·as·build·environment·variables\n\n**Job·Configuration**··\n1.·**Configure**·the·project,·and·go·to·the·**Build·Environment**·section.\n1.·Enable·**Prepare·SonarScanner·environment**·to·allow·the·injection·of·SonarQube·server·values·into·this·particular·job.·If·multiple·SonarQube·instances·are·configured,·you·will·be·able·to·choose·which·one·to·use.\nOnce·the·environment·variables·are·available,·use·them·in·a·standard·Maven·build·step·(Invoke·top-level·Maven·targets)·by·setting·the·Goals·to·include,·or·a·standard·Gradle·build·step·(Invoke·Gradle·script)·by·setting·the·Tasks·to·execute.\n\nMaven·goal:\n```\n$SONAR_MAVEN_GOAL\n```\nGradle·task:\n```\nsonarqube\n```\n\nIn·both·cases,·launching·your·analysis·may·require·authentication.·In·that·case,·make·sure·that·the·Global·Configuration·defines·a·valid·SonarQube·token.\n\n##·Analyzing·other·project·types\n\n**Global·Configuration**··\nThis·step·is·mandatory·if·you·want·to·trigger·any·of·your·SonarQube·analyses·with·the·SonarScanner.·You·can·define·as·many·scanner·instances·as·you·wish.·Then·for·each·Jenkins·job,·you·will·be·able·to·choose·which·launcher·to·use·to·run·the·SonarQube·analysis.\n\n1.·Log·into·Jenkins·as·an·administrator·and·go·to·**Manage·Jenkins·>·Global·Tool·Configuration**\n1.·Scroll·down·to·the·SonarScanner·configuration·section·and·click·on·Add·SonarScanner.·It·is·based·on·the·typical·Jenkins·tool·auto-installation.·You·can·either·choose·to·point·to·an·already·installed·version·of·SonarScanner·(uncheck·'Install·automatically')·or·tell·Jenkins·to·grab·the·installer·from·a·remote·location·(check·'Install·automatically')\n\nIf·you·don't·see·a·drop-down·list·with·all·available·SonarScanner·versions·but·instead·see·an·empty·text·field·then·this·is·because·Jenkins·still·hasn't·downloaded·the·required·update·center·file·(default·period·is·1·day).·You·may·force·this·refresh·by·clicking·the·'Check·Now'·button·in·Manage·Plugins·>·Advanced·tab.\n\n**Job·Configuration**··\n1.·**Configure**·the·project,·and·go·to·the·**Build**·section.·\n1.·Add·the·SonarScanner·build·step·to·your·build.\n1.·Configure·the·SonarQube·analysis·properties.·You·can·either·point·to·an·existing·sonar-project.properties·file·or·set·the·analysis·properties·directly·in·the·**Analysis·properties**·field\n\n\n\n##·Using·a·Jenkins·pipeline\nWe·provide·a·`withSonarQubeEnv`·block·that·allows·you·to·select·the·SonarQube·server·you·want·to·interact·with.·Connection·details·you·have·configured·in·Jenkins·global·configuration·will·be·automatically·passed·to·the·scanner.\n\nIf·needed·you·can·override·the·`credentialId`·if·you·don't·want·to·use·the·one·defined·in·global·configuration·(for·example·if·you·define·credentials·at·folder·level).\n\nIf·you·only·need·the·SonarQube·environment·variables·to·be·expanded·in·the·build·context·then·you·can·override·the·`envOnly`·flag.\n```\nwithSonarQubeEnv('My·SonarQube·Server',·envOnly:·true)·{\n··//·This·expands·the·evironment·variables·SONAR_CONFIG_NAME,·SONAR_HOST_URL,·SONAR_AUTH_TOKEN·that·can·be·used·by·any·script.\n··println·${env.SONAR_HOST_URL}·\n}\n```\n\nHere·are·some·examples·for·every·scanner,·assuming·you·run·on·Unix·slaves·and·you·have·configured·a·server·named·\"My·SonarQube·Server\"·as·well·as·required·tools.·If·you·run·on·Windows·slaves,·just·replace·`sh`·with·`bat`.\n\nSonarScanner:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····def·scannerHome·=·tool·'SonarScanner·4.0';\n····withSonarQubeEnv('My·SonarQube·Server')·{·//·If·you·have·configured·more·than·one·global·server·connection,·you·can·specify·its·name\n······sh·\"${scannerHome}/bin/sonar-scanner\"\n····}\n··}\n}\n```\nSonarScanner·for·Gradle:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····withSonarQubeEnv()·{·//·Will·pick·the·global·server·connection·you·have·configured\n······sh·'./gradlew·sonarqube'\n····}\n··}\n}\n```\nSonarScanner·for·Maven:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····withSonarQubeEnv(credentialsId:·'f225455e-ea59-40fa-8af7-08176e86507a',·installationName:·'My·SonarQube·Server')·{·//·You·can·override·the·credential·to·be·used\n······sh·'mvn·org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar'\n····}\n··}\n}\n```\nSonarScanner·for·.NET:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('Build·+·SonarQube·analysis')·{\n····def·sqScannerMsBuildHome·=·tool·'Scanner·for·MSBuild·4.6'\n····withSonarQubeEnv('My·SonarQube·Server')·{\n······bat·\"${sqScannerMsBuildHome}\\\\SonarQube.Scanner.MSBuild.exe·begin·/k:myKey\"\n······bat·'MSBuild.exe·/t:Rebuild'\n······bat·\"${sqScannerMsBuildHome}\\\\SonarQube.Scanner.MSBuild.exe·end\"\n····}\n··}\n}\n```\n\n##·Pause·pipeline·until·the·Quality·Gate·is·computed\nThe·`waitForQualityGate`·step·will·pause·the·pipeline·until·SonarQube·analysis·is·completed·and·returns·Quality·Gate·status.\n\n###·Pre-requisites:\n*·Configure·a·webhook·in·your·SonarQube·server·pointing·to·`<your·Jenkins·instance>/sonarqube-webhook/`·\n*·Use·`withSonarQubeEnv`·step·in·your·pipeline·(so·that·SonarQube·taskId·is·correctly·attached·to·the·pipeline·context).\n\n\nScripted·pipeline·example:\n```\nnode·{\n··stage('SCM')·{\n····git·'https://github.com/foo/bar.git'\n··}\n··stage('SonarQube·analysis')·{\n····withSonarQubeEnv('My·SonarQube·Server')·{\n······sh·'mvn·clean·package·sonar:sonar'\n····}·//·submitted·SonarQube·taskId·is·automatically·attached·to·the·pipeline·context\n··}\n}\n··\n//·No·need·to·occupy·a·node\nstage(\"Quality·Gate\"){\n··timeout(time:·1,·unit:·'HOURS')·{·//·Just·in·case·something·goes·wrong,·pipeline·will·be·killed·after·a·timeout\n····def·qg·=·waitForQualityGate()·//·Reuse·taskId·previously·collected·by·withSonarQubeEnv\n····if·(qg.status·!=·'OK')·{\n······error·\"Pipeline·aborted·due·to·quality·gate·failure:·${qg.status}\"\n····}\n··}\n}\n```\nThanks·to·the·webhook,·the·step·is·implemented·in·a·very·lightweight·way:·no·need·to·occupy·a·node·doing·polling,·and·it·doesn't·prevent·Jenkins·to·restart·(step·will·be·restored·after·restart).·Note·that·to·prevent·race·conditions,·when·the·step·starts·(or·is·restarted)·a·direct·call·is·made·to·the·server·to·check·if·the·task·is·already·completed.\n\nDeclarative·pipeline·example:\n```\npipeline·{\n····agent·any\n····stages·{\n········stage('SCM')·{\n············steps·{\n················git·url:·'https://github.com/foo/bar.git'\n············}\n········}\n········stage('build·&&·SonarQube·analysis')·{\n············steps·{\n················withSonarQubeEnv('My·SonarQube·Server')·{\n····················//·Optionally·use·a·Maven·environment·you've·configured·already\n····················withMaven(maven:'Maven·3.5')·{\n························sh·'mvn·clean·package·sonar:sonar'\n····················}\n················}\n············}\n········}\n········stage(\"Quality·Gate\")·{\n············steps·{\n················timeout(time:·1,·unit:·'HOURS')·{\n····················//·Parameter·indicates·whether·to·set·pipeline·to·UNSTABLE·if·Quality·Gate·fails\n····················//·true·=·set·pipeline·to·UNSTABLE,·false·=·don't\n····················waitForQualityGate·abortPipeline:·true\n················}\n············}\n········}\n····}\n}\n```\n\nIf·you·want·to·run·multiple·analysis·in·the·same·pipeline·and·use·waitForQualityGate·you·have·to·do·everything·in·order:\n```\npipeline·{\n····agent·any\n····stages·{\n········stage('SonarQube·analysis·1')·{\n············steps·{\n················sh·'mvn·clean·package·sonar:sonar'\n············}\n········}\n········stage(\"Quality·Gate·1\")·{\n············steps·{\n················waitForQualityGate·abortPipeline:·true\n············}\n········}\n········stage('SonarQube·analysis·2')·{\n············steps·{\n················sh·'gradle·sonarqube'\n············}\n········}\n········stage(\"Quality·Gate·2\")·{\n············steps·{\n················waitForQualityGate·abortPipeline:·true\n············}\n········}\n····}\n}\n```\n\n###·Configuring·a·webhook·secret\n\nIf·you·want·to·verify·the·webhook·payload·that·is·sent·to·Jenkins,·you·can·add·a·secret·to·your·webhook·on·SonarQube.\n\nTo·set·the·secret:·\n\n1.·In·Jenkins,·navigate·to·**Manage·Jenkins·>·Configure·System·>·SonarQube·Server·>·Advanced·>·Webhook·Secret**·and·click·the·**Add**·button.\n1.·Select·**Secret·text**·and·give·the·secret·an·ID.\n1.·Select·the·secret·from·the·dropdown·menu.\n\nIf·you·want·to·override·the·webhook·secret·on·a·project·level,·you·can·add·the·secret·to·Jenkins·and·then·reference·the·secret·ID·when·calling·`waitForQualityGate`.\n\n····waitForQualityGate(webhookSecretId:·'yourSecretID')····\nif·your·pipeline·is·declarative·or\n\n····waitForQualityGate·webhookSecretId:·'yourSecretID'\nif·your·pipeline·is·scripted.\n" |
697 | ············},·{ | 697 | ············},·{ |
698 | ················path:·"analysis/scan/sonarscanner-for-maven", | 698 | ················path:·"analysis/scan/sonarscanner-for-maven", |
699 | ················content:·'---\ntitle:·SonarScanner·for·Maven\nurl:·/analysis/scan/sonarscanner-for-maven/\n---\n\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey="scannermaven"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner-maven.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\nThe·SonarScanner·for·Maven·is·recommended·as·the·default·scanner·for·Maven·projects.\n\nThe·ability·to·execute·the·SonarQube·analysis·via·a·regular·Maven·goal·makes·it·available·anywhere·Maven·is·available·(developer·build,·CI·server,·etc.),·without·the·need·to·manually·download,·setup,·and·maintain·a·SonarQube·Runner·installation.·The·Maven·build·already·has·much·of·the·information·needed·for·SonarQube·to·successfully·analyze·a·project.·By·preconfiguring·the·analysis·based·on·that·information,·the·need·for·manual·configuration·is·reduced·significantly.·\n\n##·Prerequisites\n*·Maven·3.x\n*·At·least·the·minimal·version·of·Java·supported·by·your·SonarQube·server·is·in·use·\n\n##·Global·Settings·\n\nEdit·the·[settings.xml](http://maven.apache.org/settings.html)·file,·located·in·`$MAVEN_HOME/conf`·or·`~/.m2`,·to·set·the·plugin·prefix·and·optionally·the·SonarQube·server·URL.\n\nExample:\n```\n<settings>\n····<pluginGroups>\n········<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>\n····</pluginGroups>\n····<profiles>\n········<profile>\n············<id>sonar</id>\n············<activation>\n················<activeByDefault>true</activeByDefault>\n············</activation>\n············<properties>\n················\x3c!--·Optional·URL·to·server.·Default·value·is·http://localhost:9000·--\x3e\n················<sonar.host.url>\n··················http://myserver:9000\n················</sonar.host.url>\n············</properties>\n········</profile>\n·····</profiles>\n</settings>\n```\n\n##·Analyzing\nAnalyzing·a·Maven·project·consists·of·running·a·Maven·goal:·`sonar:sonar`·from·the·directory·that·holds·the·main·project·`pom.xml`.·You·need·to·pass·an·[authentication·token](/user-guide/user-token/)·using·the·`sonar.login`·property·in·your·command·line.\n\n```\nmvn·clean·verify·sonar:sonar·-Dsonar.login=myAuthenticationToken\n```\n\nIn·some·situations·you·may·want·to·run·the·`sonar:sonar`·goal·as·a·dedicated·step.·Be·sure·to·use·`install`·as·first·step·for·multi-module·projects\n```\nmvn·clean·install\nmvn·sonar:sonar·-Dsonar.login=myAuthenticationToken\n```\n\nTo·specify·the·version·of·sonar-maven-plugin·instead·of·using·the·latest:\n```\nmvn·org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar\n```\n\nTo·get·coverage·information,·you\'ll·need·to·generate·the·coverage·report·before·the·analysis.·\n\n##·Configuring·Analysis\nMost·analysis·properties·will·be·read·from·your·project.·If·you·would·like·override·the·default·values·of·specify·additional·parameters,·configure·the·parameter·names·found·on·the·[Analysis·Parameters](/analysis/analysis-parameters/)·page·in·the·`<properties>`·section·of·your·pom.xml·like·this:\n```\n<properties>\n··<sonar.buildString>·[...]·</sonar.buildString>\n</properties>\n·```\n\n##·Sample·Project\nTo·help·you·get·started,·a·simple·project·sample·is·available·here:·https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven\n\n##·Excluding·a·module·from·analysis\n*·define·property·`<sonar.skip>true</sonar.skip>`·in·the·`pom.xml`·of·the·module·you·want·to·exclude\n*·use·build·profiles·to·exclude·some·module·(like·for·integration·tests)\n*·use·Advanced·Reactor·Options·(such·as·"-pl").·For·example·`mvn·sonar:sonar·-pl·!module2`\n\n##·How·to·Fix·Version·of·Maven·Plugin\nIt·is·recommended·to·lock·down·versions·of·Maven·plugins:\n```\n<build>\n··<pluginManagement>\n····<plugins>\n······<plugin>\n········<groupId>org.sonarsource.scanner.maven</groupId>\n········<artifactId>sonar-maven-plugin</artifactId>\n········<version>3.7.0.1746</version>\n······</plugin>\n····</plugins>\n··</pluginManagement>\n</build>\n```\n\n##·Troubleshooting\n**If·you·get·a·java.lang.OutOfMemoryError**··\nSet·the·`MAVEN_OPTS`·environment·variable,·like·this·in·*nix·environments:\n```\nexport·MAVEN_OPTS="-Xmx512m"\n```\nIn·Windows·environments,·avoid·the·double-quotes,·since·they·get·misinterpreted.\n```\nset·MAVEN_OPTS=-Xmx512m\n```\n' | 699 | ················content:·'---\ntitle:·SonarScanner·for·Maven\nurl:·/analysis/scan/sonarscanner-for-maven/\n---\n\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey="scannermaven"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner-maven.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\nThe·SonarScanner·for·Maven·is·recommended·as·the·default·scanner·for·Maven·projects.\n\nThe·ability·to·execute·the·SonarQube·analysis·via·a·regular·Maven·goal·makes·it·available·anywhere·Maven·is·available·(developer·build,·CI·server,·etc.),·without·the·need·to·manually·download,·setup,·and·maintain·a·SonarQube·Runner·installation.·The·Maven·build·already·has·much·of·the·information·needed·for·SonarQube·to·successfully·analyze·a·project.·By·preconfiguring·the·analysis·based·on·that·information,·the·need·for·manual·configuration·is·reduced·significantly.·\n\n##·Prerequisites\n*·Maven·3.x\n*·At·least·the·minimal·version·of·Java·supported·by·your·SonarQube·server·is·in·use·\n\n##·Global·Settings·\n\nEdit·the·[settings.xml](http://maven.apache.org/settings.html)·file,·located·in·`$MAVEN_HOME/conf`·or·`~/.m2`,·to·set·the·plugin·prefix·and·optionally·the·SonarQube·server·URL.\n\nExample:\n```\n<settings>\n····<pluginGroups>\n········<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>\n····</pluginGroups>\n····<profiles>\n········<profile>\n············<id>sonar</id>\n············<activation>\n················<activeByDefault>true</activeByDefault>\n············</activation>\n············<properties>\n················\x3c!--·Optional·URL·to·server.·Default·value·is·http://localhost:9000·--\x3e\n················<sonar.host.url>\n··················http://myserver:9000\n················</sonar.host.url>\n············</properties>\n········</profile>\n·····</profiles>\n</settings>\n```\n\n##·Analyzing\nAnalyzing·a·Maven·project·consists·of·running·a·Maven·goal:·`sonar:sonar`·from·the·directory·that·holds·the·main·project·`pom.xml`.·You·need·to·pass·an·[authentication·token](/user-guide/user-token/)·using·the·`sonar.login`·property·in·your·command·line.\n\n```\nmvn·clean·verify·sonar:sonar·-Dsonar.login=myAuthenticationToken\n```\n\nIn·some·situations·you·may·want·to·run·the·`sonar:sonar`·goal·as·a·dedicated·step.·Be·sure·to·use·`install`·as·first·step·for·multi-module·projects\n```\nmvn·clean·install\nmvn·sonar:sonar·-Dsonar.login=myAuthenticationToken\n```\n\nTo·specify·the·version·of·sonar-maven-plugin·instead·of·using·the·latest:\n```\nmvn·org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar\n```\n\nTo·get·coverage·information,·you\'ll·need·to·generate·the·coverage·report·before·the·analysis.·\n\n##·Configuring·Analysis\nMost·analysis·properties·will·be·read·from·your·project.·If·you·would·like·override·the·default·values·of·specify·additional·parameters,·configure·the·parameter·names·found·on·the·[Analysis·Parameters](/analysis/analysis-parameters/)·page·in·the·`<properties>`·section·of·your·pom.xml·like·this:\n```\n<properties>\n··<sonar.buildString>·[...]·</sonar.buildString>\n</properties>\n·```\n\n##·Sample·Project\nTo·help·you·get·started,·a·simple·project·sample·is·available·here:·https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-maven\n\n##·Excluding·a·module·from·analysis\n*·define·property·`<sonar.skip>true</sonar.skip>`·in·the·`pom.xml`·of·the·module·you·want·to·exclude\n*·use·build·profiles·to·exclude·some·module·(like·for·integration·tests)\n*·use·Advanced·Reactor·Options·(such·as·"-pl").·For·example·`mvn·sonar:sonar·-pl·!module2`\n\n##·How·to·Fix·Version·of·Maven·Plugin\nIt·is·recommended·to·lock·down·versions·of·Maven·plugins:\n```\n<build>\n··<pluginManagement>\n····<plugins>\n······<plugin>\n········<groupId>org.sonarsource.scanner.maven</groupId>\n········<artifactId>sonar-maven-plugin</artifactId>\n········<version>3.7.0.1746</version>\n······</plugin>\n····</plugins>\n··</pluginManagement>\n</build>\n```\n\n##·Troubleshooting\n**If·you·get·a·java.lang.OutOfMemoryError**··\nSet·the·`MAVEN_OPTS`·environment·variable,·like·this·in·*nix·environments:\n```\nexport·MAVEN_OPTS="-Xmx512m"\n```\nIn·Windows·environments,·avoid·the·double-quotes,·since·they·get·misinterpreted.\n```\nset·MAVEN_OPTS=-Xmx512m\n```\n' |
700 | ············},·{ | 700 | ············},·{ |
701 | ················path:·"analysis/scan/sonarscanner-for-msbuild", | 701 | ················path:·"analysis/scan/sonarscanner-for-msbuild", |
702 | ················content:·'---\nurl:·/analysis/scan/sonarscanner-for-msbuild/\ntitle:·SonarScanner·for·.NET\n---\n\n\x3c!--·sonarqube·--\x3e\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey="scannermsbuild"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner-msbuild.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\x3c!--·/sonarqube·--\x3e\n\n\x3c!--·sonarcloud·--\x3e\n[[info]]\n|·**Download·SonarScanner·for·.NET·5.2.0**·-·[Issue·Tracker](https://github.com/SonarSource/sonar-scanner-msbuild/issues)·-·[Source](https://github.com/SonarSource/sonar-scanner-msbuild)\n|\n|·[Standalone·executables](https://github.com/SonarSource/sonar-scanner-msbuild/releases/tag/5.2.0.29862)·|\n|·[.NET·Core·Global·Tool](https://www.nuget.org/packages/dotnet-sonarscanner)\n\x3c!--·/sonarcloud·--\x3e\n\n[[info]]\n|·Since·version·5.0,·the·SonarScanner·for·MSBuild·is·now·the·SonarScanner·for·.NET.·\n|·Documentation·is·updated·with·that·new·name,·artifacts·and·links·will·remain·with·the·old·name·for·now.\n\nThe·SonarScanner·for·.NET·is·the·recommended·way·to·launch·an·analysis·for·projects/solutions·using·MSBuild·or·dotnet·command·as·a·build·tool.·It·is·the·result·of·a·[collaboration·between·SonarSource·and·Microsoft](https://www.sonarqube.org/announcing-sonarqube-integration-with-msbuild-and-team-build/).\n\nSonarScanner·for·.NET·is·distributed·as·a·standalone·command·line·executable,·as·an·extension·for·\x3c!--·sonarcloud·--\x3e[Azure·DevOps](/analysis/scan/sonarscanner-for-azure-devops/)\x3c!--·/sonarcloud·--\x3e\x3c!--·sonarqube·--\x3e[Azure·DevOps·Server](/analysis/scan/sonarscanner-for-azure-devops/)\x3c!--·/sonarqube·--\x3e,·and·as·a·plugin·for·[Jenkins](/analysis/scan/sonarscanner-for-jenkins/).\n\nIt·supports·.Net·Core·on·every·platform·(Windows,·macOS,·Linux).\n\n##·Prerequisites\n\x3c!--·sonarqube·--\x3e\n*·At·least·the·minimal·version·of·Java·supported·by·your·SonarQube·server\n\x3c!--·/sonarqube·--\x3e\n\x3c!--·sonarcloud·--\x3e\n*·Java·11·or·greater\n\x3c!--·/sonarcloud·--\x3e\n*·The·SDK·corresponding·to·your·build·system:\n···*·[.NET·Framework·v4.6](https://www.microsoft.com/en-us/download/details.aspx?id=53344)·-·either·[Build·Tools·for·Visual·Studio·2015·Update·3](https://go.microsoft.com/fwlink/?LinkId=615458)·or·the·[Build·Tools·for·Visual·Studio·2017](https://www.visualstudio.com/downloads/)\n···*·[.NET·Core·SDK·2.0·and·above](https://dotnet.microsoft.com/download)·(for·.NET·Core·version·of·the·scanner·or·if·you·plan·to·use·[.NET·Core·Global·Tool](https://www.nuget.org/packages/dotnet-sonarscanner)\n\n[[info]]\n|·The·flavor·used·to·compile·the·Scanner·for·.NET·(either·.NET·Framework,·.NET·Core·or·.NET)·is·independent·of·the·.NET·version·the·\n|·project·you·want·to·analyze·has·been·built·with.·Concretely,·you·can·analyze·.NET·Core·code·with·the·.NET·Framework·version·of·\n|·the·Scanner.·It\'s·only·relevant·depending·on·your·OS,·and·on·the·versions·of·.NET·SDKs·that·are·installed·on·your·build·machine.\n\n\x3c!--·sonarqube·--\x3e\n###·Compatibility\n\nScanner·Version|SonarQube\n---|---\n5.x|·LTS·6.7+\n4.x|·LTS·6.7+\n\x3c!--·/sonarqube·--\x3e\n##·Installation\n\n###·Standalone·executable\n\n*·Expand·the·downloaded·file·into·the·directory·of·your·choice.·We\'ll·refer·to·it·as·`$install_directory`·in·the·next·steps.\n··*·On·Windows,·you·might·need·to·unblock·the·ZIP·file·first·(right-click·**file·>·Properties·>·Unblock**).\n··*·On·Linux/OSX·you·may·need·to·set·execute·permissions·on·the·files·in·`$install_directory/sonar-scanner-(version)/bin`.\n\n*·Uncomment,·and·update·the·global·settings·to·point·to·\x3c!--·sonarqube·--\x3eyour·SonarQube·server\x3c!--·/sonarqube·--\x3e\x3c!--·sonarcloud·--\x3eSonarCloud\x3c!--·/sonarcloud·--\x3e·by·editing·`$install_directory/SonarQube.Analysis.xml`.·Values·set·in·this·file·will·be·applied·to·all·analyses·of·all·projects·unless·overwritten·locally.··\nConsider·setting·file·system·permissions·to·restrict·access·to·this·file.:\n\n```xml\n<SonarQubeAnalysisProperties··xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"·xmlns:xsd="http://www.w3.org/2001/XMLSchema"·xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">\n··<Property·Name="sonar.host.url">\x3c!--·sonarqube·--\x3ehttp://localhost:9000\x3c!--·/sonarqube·--\x3e\x3c!--·sonarcloud·--\x3ehttps://sonarcloud.io\x3c!--·/sonarcloud·--\x3e</Property>\n··<Property·Name="sonar.login">[my-user-token]</Property>\n</SonarQubeAnalysisProperties>\n```\n\n*·Add·`$install_directory`·to·your·PATH·environment·variable.\n\n###·.NET·Core·Global·Tool\n\n```bash\ndotnet·tool·install·--global·dotnet-sonarscanner·--version·x.x.x\n```\n\nThe·_--version_·argument·is·optional.·If·it·is·omitted·the·latest·version·will·be·installed.·Full·list·of·releases·is·available·on·the·[NuGet·page](https://www.nuget.org/packages/dotnet-sonarscanner)\n\n.NET·Core·Global·Tool·is·available·from·.NET·Core·2.1+\n\n\x3c!--·sonarqube·--\x3e\n###·On·Linux/OSX,·if·your·SonarQube·server·is·secured\n\n1.·Copy·the·server\'s·CA·certs·to·`/usr/local/share/ca-certificates`\n2.·Run·`sudo·update-ca-certificates`\n\x3c!--·/sonarqube·--\x3e\n\n##·Use\n\n[[info]]\n|·You·can·invoke·the·Scanner·using·arguments·with·both·dash·(-)·or·forward-slash·(/)·separators.\n|·Example·:·SonarScanner.MSBuild.exe·begin·/k:"project-key"·or·SonarScanner.MSBuild.exe·begin·-k:"project-key"·will·work.\n\nThere·are·two·versions·of·the·SonarScanner·for·.NET.·In·the·following·commands,·you·need·to·pass·an·[authentication·token](/user-guide/user-token/)·using·the·`sonar.login`·property.\n\n###·"Classic"·.NET·Framework·Invocation\n\nThe·first·version·is·based·on·the·"classic"·.NET·Framework.·To·use·it,·execute·the·following·commands·from·the·root·folder·of·your·project:\n\n```\nSonarScanner.MSBuild.exe·begin·/k:"project-key"·\x3c!--·sonarcloud·--\x3e/o:"<organization>"·\x3c!--·/sonarcloud·--\x3e/d:sonar.login="<token>"\nMSBuild.exe·<path·to·solution.sln>·/t:Rebuild\nSonarScanner.MSBuild.exe·end·/d:sonar.login="<token>"\n```\n\nNote:·On·macOS·or·Linux,·you·can·also·use·`mono·<path·to·SonarScanner.MSBuild.exe>`.\n\n###·.NET·Core·and·.NET·Core·Global·Tool·Invocation\n\nThe·second·version·is·based·on·.NET·Core·which·has·a·very·similar·usage:\n\n```bash\ndotnet·<path·to·SonarScanner.MSBuild.dll>·begin·/k:"project-key"·\x3c!--·sonarcloud·--\x3e/o:"<organization>"·\x3c!--·/sonarcloud·--\x3e/d:sonar.login="<token>"\ndotnet·build·<path·to·solution.sln>\ndotnet·<path·to·SonarScanner.MSBuild.dll>·end·/d:sonar.login="<token>"·\n```\n\nThe·.NET·Core·version·can·also·be·used·as·a·.NET·Core·Global·Tool.\nAfter·installing·the·Scanner·as·a·global·tool·as·described·above·it·can·be·invoked·as·follows:\n\n```bash\ndotnet·tool·install·--global·dotnet-sonarscanner\ndotnet·sonarscanner·begin·/k:"project-key"·\x3c!--·sonarcloud·--\x3e/o:"<organization>"·\x3c!--·/sonarcloud·--\x3e/d:sonar.login="<token>"\ndotnet·build·<path·to·solution.sln>\ndotnet·sonarscanner·end·/d:sonar.login="<token>"\n```\n\nIn·summary,·the·invocation·of·the·SonarScanner·for·.NET·will·depend·on·the·scanner·flavor:\n\n·Scanner·Flavor·|·Invocation\n·---·|·---\n·.NET·5·|·`dotnet·<path·to·SonarScanner.MSBuild.dll>`·etc.\n·.NET·Core·Global·Tool·|·`dotnet·sonarscanner·begin`·etc.\n·.NET·Core·2.0+·|·`dotnet·<path·to·SonarScanner.MSBuild.dll>`·etc.\n·.NET·Framework·4.6+|`SonarScanner.MSBuild.exe·begin`·etc.\n\nNotes:\n\n*·The·.NET·Core·version·of·the·scanner·does·not·support·TFS·XAML·builds·and·automatic·finding/conversion·of·Code·Coverage·files.·Apart·from·that,·all·versions·of·the·Scanner·have·the·same·capabilities·and·command·line·arguments.\n\n##·Analysis·steps\n###·Begin\nThe·begin·step·is·executed·when·you·add·the·`begin`·command·line·argument.·It·hooks·into·the·build·pipeline,·downloads·{instance}·quality·profiles·and·settings·and·prepares·your·project·for·the·analysis.\n\nCommand·Line·Parameters:\n\nParameter|Description\n---|---\n`/k:<project-key>`|[required]·Specifies·the·key·of·the·analyzed·project·in·{instance}\n`/n:<project·name>`|[optional]·Specifies·the·name·of·the·analyzed·project·in·{instance}.·Adding·this·argument·will·overwrite·the·project·name·in·{instance}·if·it·already·exists.\n`/v:<version>`|[recommended]·Specifies·the·version·of·your·project.\n\x3c!--·sonarcloud·--\x3e·`/o:<organization>`|[required]·Specifies·the·name·of·the·target·organization·in·SonarCloud.·\x3c!--·/sonarcloud·--\x3e\n`/d:sonar.login=<token>·or·<username>`|·[recommended]·Specifies·the·[authentication·token](/user-guide/user-token/)·or·username·used·to·authenticate·with·to·{instance}.·If·this·argument·is·added·to·the·begin·step,·it·must·also·be·added·to·the·end·step.\n`/d:sonar.password=<password>`|[optional]·Specifies·the·password·for·the·{instance}·username·in·the·`sonar.login`·argument.·This·argument·is·not·needed·if·you·use·authentication·token.·If·this·argument·is·added·to·the·begin·step,·it·must·also·be·added·on·the·end·step.\n`/d:sonar.verbose=true`|[optional]·Sets·the·logging·verbosity·to·detailed.·Add·this·argument·before·sending·logs·for·troubleshooting.\n`/d:sonar.dotnet.excludeTestProjects=true`|[optional]·Excludes·Test·Projects·from·analysis.·Add·this·argument·to·improve·build·performance·when·issues·should·not·be·detected·in·Test·Projects.\n`/d:<analysis-parameter>=<value>`|[optional]·Specifies·an·additional·{instance}·[analysis·parameter](/analysis/analysis-parameters/),·you·can·add·this·argument·multiple·times.\n\nFor·detailed·information·about·all·available·parameters,·see·[Analysis·Parameters](/analysis/analysis-parameters/).\n\n[[warning]]\n|··The·"begin"·step·will·modify·your·build·like·this:\n|·*·the·active·`CodeAnalysisRuleSet`·will·be·updated·to·match·the·{instance}·quality·profile\n|·*·`WarningsAsErrors`·will·be·turned·off\n|\n|·If·your·build·process·cannot·tolerate·these·changes·we·recommend·creating·a·second·build·job·for·{instance}·analysis.\n\n###·Build\nBetween·the·`begin`·and·`end`·steps,·you·need·to·build·your·project,·execute·tests·and·generate·code·coverage·data.·This·part·is·specific·to·your·needs·and·it·is·not·detailed·here.\n\n###·End\nThe·end·step·is·executed·when·you·add·the·"end"·command·line·argument.·It·cleans·the·MSBuild/dotnet·build·hooks,·collects·the·analysis·data·generated·by·the·build,·the·test·results,·the·code·coverage·and·then·uploads·everything·to·{instance}\n\nThere·are·only·two·additional·arguments·that·are·allowed·for·the·end·step:\n\nParameter|Description\n---|---\n`/d:sonar.login=<token>·or·<username>`|·This·argument·is·required·if·it·was·added·to·the·begin·step.\n`/d:sonar.password=<password>`|·This·argument·is·required·if·it·was·added·to·the·begin·step·and·you·are·not·using·an·authentication·token.\n\n###·Known·Limitations\n\n*·MSBuild·versions·older·than·14·are·not·supported.\n*·Web·Application·projects·are·supported.·Legacy·Web·Site·projects·are·not.\n*·Projects·targeting·multiple·frameworks·and·using·preprocessor·directives·could·have·slightly·inaccurate·metrics·(lines·of·code,·complexity,·etc.)·because·the·metrics·are·calculated·only·from·the·first·of·the·built·targets.\n\n##·Code·Coverage\n\nIn·a·Azure·DevOps·/·TFS·environment,·test·files·are·automatically·retrieved·following·this·search\n*·Search·for·.trx·files·in·any·TestResults·folder·located·under·the·$Build.SourcesDirectory·path\n*·If·not·found,·then·a·fallback·search·is·made·against·$Agent.TempDirectory\n\nOnce·trx·files·have·been·found,·their·`.coverage`·counterpart·are·searched·as·well·and·the·scanner·tries·to·convert·them·to·`.coveragexml`·files·that·will·be·uploaded·to·{instance}.\nCodeCoverage.exe·tool·is·used·for·that,·and·the·scanner·also·needs·to·find·a·path·to·that·tool,·following·this·search·path\n*·Search·for·the·presence·of·`VsTestToolsInstallerInstalledToolLocation`·environment·variable,·set·by·the·VsTestToolsPlatformInstaller·task·or·by·the·user\n*·If·not·found,·search·for·either·the·presence·of·that·tool·in·well-known·installation·path,·or·via·the·registry.\n\nAs·stated·above,·this·will·work·only·with·the·.NET·4.6·flavor·of·the·Scanner.\n\n##·Excluding·projects·from·analysis\n\nSome·project·types,·such·as·[Microsoft·Fakes](https://msdn.microsoft.com/en-us/library/hh549175.aspx),·are·automatically·excluded·from·analysis.·To·manually·exclude·a·different·type·of·project·from·the·analysis,·place·the·following·in·its·.xxproj·file.\n\n```xml\n\x3c!--·in·.csproj·--\x3e\n<PropertyGroup>\n··\x3c!--·Exclude·the·project·from·analysis·--\x3e\n··<SonarQubeExclude>true</SonarQubeExclude>\n</PropertyGroup>\n```\n\n##·Advanced·topics\n\n**Analyzing·MSBuild·12·projects·with·MSBuild·14**··\nThe·Sonar·Scanner·for·.NET·requires·your·project·to·be·built·with·MSBuild·14.0.·We·recommend·installing·Visual·Studio·2015·update·3·or·later·on·the·analysis·machine·in·order·to·benefit·from·the·integration·and·features·provided·with·the·Visual·Studio·ecosystem·(VSTest,·MSTest·unit·tests,·etc.).\n\nProjects·targeting·older·versions·of·the·.NET·Framework·can·be·built·using·MSBuild·14.0·by·setting·the·"TargetFrameworkVersion"·MSBuild·property·as·documented·by·Microsoft:\n\n*·[How·to:·Target·a·Version·of·the·.NET·Framework](https://msdn.microsoft.com/en-us/library/bb398202.aspx)\n*·[MSBuild·Target·Framework·and·Target·Platform](https://msdn.microsoft.com/en-us/library/hh264221.aspx)\n\nIf·you·do·not·want·to·switch·your·production·build·to·MSBuild·14.0,·you·can·set·up·a·separate·build·dedicated·to·the·{instance}·analysis.\n\n**Detection·of·test·projects**\n\nYou·can·read·a·full·description·on·that·subject·on·our·wiki·[here](https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects).\n\n**Per-project·analysis·parameters**\nSome·analysis·parameters·can·be·set·for·a·single·MSBuild·project·by·adding·them·to·its·.csproj·file.\n\n```xml\n\x3c!--·in·.csproj·--\x3e\n<ItemGroup>\n··<SonarQubeSetting·Include="sonar.stylecop.projectFilePath">\n····<Value>$(MSBuildProjectFullPath)</Value>\n··</SonarQubeSetting>\n</ItemGroup>\n```\n\n**Analyzing·languages·other·than·C#·and·VB**\n\nBy·default,·SonarScanner·for·.NET·will·only·analyze·C#·and·VB·files·in·your·project.·To·enable·the·analysis·of·other·types·of·files,·these·files·must·be·listed·in·the·MSBuild·project·file·(the·`.csproj`·or·`.vbproj`·file).\n\nMore·specifically,·any·files·included·by·an·element·of·one·of·the·`ItemTypes`·in\n[this·list](https://github.com/SonarSource/sonar-scanner-msbuild/blob/master/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets#L112)\nwill·be·analyzed·automatically.·For·example,·the·following·line·in·your·`.csproj`·or·`.vbproj`·file\n\n```\n<Content·Include="foo\\bar\\*.js"·/>\n```\n\nwill·enable·the·analysis·of·all·JS·files·in·the·directory·`foo\\bar`·because·`Content`·is·one·of·the·`ItemTypes`·whose·includes·are·automatically·analyzed.\n\nYou·can·also·add·`ItemTypes`·to·the·default·list·by·following·the·directions·[here](https://github.com/SonarSource/sonar-scanner-msbuild/blob/master/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets#L75).\n\nYou·can·check·which·files·the·scanner·will·analyze·by·looking·in·the·file·.sonarqube\\out\\sonar-project.properties·after·MSBuild·has·finished.\n\n**Using·SonarScanner·for·.NET·with·a·Proxy**··\nOn·build·machines·that·connect·to·the·Internet·through·a·proxy·server·you·might·experience·difficulties·connecting·to·{instance}.·To·instruct·the·Java·VM·to·use·the·system·proxy·settings,·you·need·to·set·the·following·environment·variable·before·running·the·SonarScanner·for·.NET:\n\n```bash\nSONAR_SCANNER_OPTS·=·"-Djava.net.useSystemProxies=true"\n```\n\nTo·instruct·the·Java·VM·to·use·specific·proxy·settings·or·when·there·is·no·system-wide·configuration·use·the·following·value:\n\n```bash\nSONAR_SCANNER_OPTS·=·"-Dhttp.proxyHost=yourProxyHost·-Dhttp.proxyPort=yourProxyPort"\n```\nWhere·_yourProxyHost_·and·_yourProxyPort_·are·the·hostname·and·the·port·of·your·proxy·server.·There·are·additional·proxy·settings·for·HTTPS,·authentication·and·exclusions·that·could·be·passed·to·the·Java·VM.·For·more·information·see·the·following·article:·https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html.\n\nHTTP_PROXY,·HTTPS_PROXY,·ALL_PROXY·and·NO_PROXY·will·be·automatically·recognized·and·use·to·make·call·against·{instance}.·The·Scanner·for·.NET·makes·HTTP·calls,·independant·from·the·settings·above·concerning·the·Java·VM,·to·fetch·the·Quality·Profile·and·other·useful·settings·for·the·"end"·step.\n\n##·Known·issues\n\n**I·have·multiple·builds·in·the·same·pipeline,·each·of·them·getting·analyzed·even·if·the·Run·Code·Analysis·has·already·been·executed**\n\nWe·don\'t·uninstall·the·global·`ImportBefore`·targets·to·support·concurrent·analyses·on·the·same·machine.·Main·effect·is·that·if·you·build·a·solution·where·a·.sonarqube·folder·is·located·nearby,·then·the·sonar-dotnet·analyzer·will·be·executed·along·your·build·task.\n\nTo·avoid·that,·you·can·disable·the·targets·file·by·adding·a·build·parameter:\n```\nmsbuild·/p:SonarQubeTargetsImported=true\ndotnet·build·-p:SonarQubeTargetsImported=true\n```\n' | 702 | ················content:·'---\nurl:·/analysis/scan/sonarscanner-for-msbuild/\ntitle:·SonarScanner·for·.NET\n---\n\n\x3c!--·sonarqube·--\x3e\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey="scannermsbuild"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner-msbuild.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\x3c!--·/sonarqube·--\x3e\n\n\x3c!--·sonarcloud·--\x3e\n[[info]]\n|·**Download·SonarScanner·for·.NET·5.2.0**·-·[Issue·Tracker](https://github.com/SonarSource/sonar-scanner-msbuild/issues)·-·[Source](https://github.com/SonarSource/sonar-scanner-msbuild)\n|\n|·[Standalone·executables](https://github.com/SonarSource/sonar-scanner-msbuild/releases/tag/5.2.0.29862)·|\n|·[.NET·Core·Global·Tool](https://www.nuget.org/packages/dotnet-sonarscanner)\n\x3c!--·/sonarcloud·--\x3e\n\n[[info]]\n|·Since·version·5.0,·the·SonarScanner·for·MSBuild·is·now·the·SonarScanner·for·.NET.·\n|·Documentation·is·updated·with·that·new·name,·artifacts·and·links·will·remain·with·the·old·name·for·now.\n\nThe·SonarScanner·for·.NET·is·the·recommended·way·to·launch·an·analysis·for·projects/solutions·using·MSBuild·or·dotnet·command·as·a·build·tool.·It·is·the·result·of·a·[collaboration·between·SonarSource·and·Microsoft](https://www.sonarqube.org/announcing-sonarqube-integration-with-msbuild-and-team-build/).\n\nSonarScanner·for·.NET·is·distributed·as·a·standalone·command·line·executable,·as·an·extension·for·\x3c!--·sonarcloud·--\x3e[Azure·DevOps](/analysis/scan/sonarscanner-for-azure-devops/)\x3c!--·/sonarcloud·--\x3e\x3c!--·sonarqube·--\x3e[Azure·DevOps·Server](/analysis/scan/sonarscanner-for-azure-devops/)\x3c!--·/sonarqube·--\x3e,·and·as·a·plugin·for·[Jenkins](/analysis/scan/sonarscanner-for-jenkins/).\n\nIt·supports·.Net·Core·on·every·platform·(Windows,·macOS,·Linux).\n\n##·Prerequisites\n\x3c!--·sonarqube·--\x3e\n*·At·least·the·minimal·version·of·Java·supported·by·your·SonarQube·server\n\x3c!--·/sonarqube·--\x3e\n\x3c!--·sonarcloud·--\x3e\n*·Java·11·or·greater\n\x3c!--·/sonarcloud·--\x3e\n*·The·SDK·corresponding·to·your·build·system:\n···*·[.NET·Framework·v4.6](https://www.microsoft.com/en-us/download/details.aspx?id=53344)·-·either·[Build·Tools·for·Visual·Studio·2015·Update·3](https://go.microsoft.com/fwlink/?LinkId=615458)·or·the·[Build·Tools·for·Visual·Studio·2017](https://www.visualstudio.com/downloads/)\n···*·[.NET·Core·SDK·2.0·and·above](https://dotnet.microsoft.com/download)·(for·.NET·Core·version·of·the·scanner·or·if·you·plan·to·use·[.NET·Core·Global·Tool](https://www.nuget.org/packages/dotnet-sonarscanner)\n\n[[info]]\n|·The·flavor·used·to·compile·the·Scanner·for·.NET·(either·.NET·Framework,·.NET·Core·or·.NET)·is·independent·of·the·.NET·version·the·\n|·project·you·want·to·analyze·has·been·built·with.·Concretely,·you·can·analyze·.NET·Core·code·with·the·.NET·Framework·version·of·\n|·the·Scanner.·It\'s·only·relevant·depending·on·your·OS,·and·on·the·versions·of·.NET·SDKs·that·are·installed·on·your·build·machine.\n\n\x3c!--·sonarqube·--\x3e\n###·Compatibility\n\nScanner·Version|SonarQube\n---|---\n5.x|·LTS·6.7+\n4.x|·LTS·6.7+\n\x3c!--·/sonarqube·--\x3e\n##·Installation\n\n###·Standalone·executable\n\n*·Expand·the·downloaded·file·into·the·directory·of·your·choice.·We\'ll·refer·to·it·as·`$install_directory`·in·the·next·steps.\n··*·On·Windows,·you·might·need·to·unblock·the·ZIP·file·first·(right-click·**file·>·Properties·>·Unblock**).\n··*·On·Linux/OSX·you·may·need·to·set·execute·permissions·on·the·files·in·`$install_directory/sonar-scanner-(version)/bin`.\n\n*·Uncomment,·and·update·the·global·settings·to·point·to·\x3c!--·sonarqube·--\x3eyour·SonarQube·server\x3c!--·/sonarqube·--\x3e\x3c!--·sonarcloud·--\x3eSonarCloud\x3c!--·/sonarcloud·--\x3e·by·editing·`$install_directory/SonarQube.Analysis.xml`.·Values·set·in·this·file·will·be·applied·to·all·analyses·of·all·projects·unless·overwritten·locally.··\nConsider·setting·file·system·permissions·to·restrict·access·to·this·file.:\n\n```xml\n<SonarQubeAnalysisProperties··xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"·xmlns:xsd="http://www.w3.org/2001/XMLSchema"·xmlns="http://www.sonarsource.com/msbuild/integration/2015/1">\n··<Property·Name="sonar.host.url">\x3c!--·sonarqube·--\x3ehttp://localhost:9000\x3c!--·/sonarqube·--\x3e\x3c!--·sonarcloud·--\x3ehttps://sonarcloud.io\x3c!--·/sonarcloud·--\x3e</Property>\n··<Property·Name="sonar.login">[my-user-token]</Property>\n</SonarQubeAnalysisProperties>\n```\n\n*·Add·`$install_directory`·to·your·PATH·environment·variable.\n\n###·.NET·Core·Global·Tool\n\n```bash\ndotnet·tool·install·--global·dotnet-sonarscanner·--version·x.x.x\n```\n\nThe·_--version_·argument·is·optional.·If·it·is·omitted·the·latest·version·will·be·installed.·Full·list·of·releases·is·available·on·the·[NuGet·page](https://www.nuget.org/packages/dotnet-sonarscanner)\n\n.NET·Core·Global·Tool·is·available·from·.NET·Core·2.1+\n\n\x3c!--·sonarqube·--\x3e\n###·On·Linux/OSX,·if·your·SonarQube·server·is·secured\n\n1.·Copy·the·server\'s·CA·certs·to·`@@HOMEBREW_PREFIX@@/share/ca-certificates`\n2.·Run·`sudo·update-ca-certificates`\n\x3c!--·/sonarqube·--\x3e\n\n##·Use\n\n[[info]]\n|·You·can·invoke·the·Scanner·using·arguments·with·both·dash·(-)·or·forward-slash·(/)·separators.\n|·Example·:·SonarScanner.MSBuild.exe·begin·/k:"project-key"·or·SonarScanner.MSBuild.exe·begin·-k:"project-key"·will·work.\n\nThere·are·two·versions·of·the·SonarScanner·for·.NET.·In·the·following·commands,·you·need·to·pass·an·[authentication·token](/user-guide/user-token/)·using·the·`sonar.login`·property.\n\n###·"Classic"·.NET·Framework·Invocation\n\nThe·first·version·is·based·on·the·"classic"·.NET·Framework.·To·use·it,·execute·the·following·commands·from·the·root·folder·of·your·project:\n\n```\nSonarScanner.MSBuild.exe·begin·/k:"project-key"·\x3c!--·sonarcloud·--\x3e/o:"<organization>"·\x3c!--·/sonarcloud·--\x3e/d:sonar.login="<token>"\nMSBuild.exe·<path·to·solution.sln>·/t:Rebuild\nSonarScanner.MSBuild.exe·end·/d:sonar.login="<token>"\n```\n\nNote:·On·macOS·or·Linux,·you·can·also·use·`mono·<path·to·SonarScanner.MSBuild.exe>`.\n\n###·.NET·Core·and·.NET·Core·Global·Tool·Invocation\n\nThe·second·version·is·based·on·.NET·Core·which·has·a·very·similar·usage:\n\n```bash\ndotnet·<path·to·SonarScanner.MSBuild.dll>·begin·/k:"project-key"·\x3c!--·sonarcloud·--\x3e/o:"<organization>"·\x3c!--·/sonarcloud·--\x3e/d:sonar.login="<token>"\ndotnet·build·<path·to·solution.sln>\ndotnet·<path·to·SonarScanner.MSBuild.dll>·end·/d:sonar.login="<token>"·\n```\n\nThe·.NET·Core·version·can·also·be·used·as·a·.NET·Core·Global·Tool.\nAfter·installing·the·Scanner·as·a·global·tool·as·described·above·it·can·be·invoked·as·follows:\n\n```bash\ndotnet·tool·install·--global·dotnet-sonarscanner\ndotnet·sonarscanner·begin·/k:"project-key"·\x3c!--·sonarcloud·--\x3e/o:"<organization>"·\x3c!--·/sonarcloud·--\x3e/d:sonar.login="<token>"\ndotnet·build·<path·to·solution.sln>\ndotnet·sonarscanner·end·/d:sonar.login="<token>"\n```\n\nIn·summary,·the·invocation·of·the·SonarScanner·for·.NET·will·depend·on·the·scanner·flavor:\n\n·Scanner·Flavor·|·Invocation\n·---·|·---\n·.NET·5·|·`dotnet·<path·to·SonarScanner.MSBuild.dll>`·etc.\n·.NET·Core·Global·Tool·|·`dotnet·sonarscanner·begin`·etc.\n·.NET·Core·2.0+·|·`dotnet·<path·to·SonarScanner.MSBuild.dll>`·etc.\n·.NET·Framework·4.6+|`SonarScanner.MSBuild.exe·begin`·etc.\n\nNotes:\n\n*·The·.NET·Core·version·of·the·scanner·does·not·support·TFS·XAML·builds·and·automatic·finding/conversion·of·Code·Coverage·files.·Apart·from·that,·all·versions·of·the·Scanner·have·the·same·capabilities·and·command·line·arguments.\n\n##·Analysis·steps\n###·Begin\nThe·begin·step·is·executed·when·you·add·the·`begin`·command·line·argument.·It·hooks·into·the·build·pipeline,·downloads·{instance}·quality·profiles·and·settings·and·prepares·your·project·for·the·analysis.\n\nCommand·Line·Parameters:\n\nParameter|Description\n---|---\n`/k:<project-key>`|[required]·Specifies·the·key·of·the·analyzed·project·in·{instance}\n`/n:<project·name>`|[optional]·Specifies·the·name·of·the·analyzed·project·in·{instance}.·Adding·this·argument·will·overwrite·the·project·name·in·{instance}·if·it·already·exists.\n`/v:<version>`|[recommended]·Specifies·the·version·of·your·project.\n\x3c!--·sonarcloud·--\x3e·`/o:<organization>`|[required]·Specifies·the·name·of·the·target·organization·in·SonarCloud.·\x3c!--·/sonarcloud·--\x3e\n`/d:sonar.login=<token>·or·<username>`|·[recommended]·Specifies·the·[authentication·token](/user-guide/user-token/)·or·username·used·to·authenticate·with·to·{instance}.·If·this·argument·is·added·to·the·begin·step,·it·must·also·be·added·to·the·end·step.\n`/d:sonar.password=<password>`|[optional]·Specifies·the·password·for·the·{instance}·username·in·the·`sonar.login`·argument.·This·argument·is·not·needed·if·you·use·authentication·token.·If·this·argument·is·added·to·the·begin·step,·it·must·also·be·added·on·the·end·step.\n`/d:sonar.verbose=true`|[optional]·Sets·the·logging·verbosity·to·detailed.·Add·this·argument·before·sending·logs·for·troubleshooting.\n`/d:sonar.dotnet.excludeTestProjects=true`|[optional]·Excludes·Test·Projects·from·analysis.·Add·this·argument·to·improve·build·performance·when·issues·should·not·be·detected·in·Test·Projects.\n`/d:<analysis-parameter>=<value>`|[optional]·Specifies·an·additional·{instance}·[analysis·parameter](/analysis/analysis-parameters/),·you·can·add·this·argument·multiple·times.\n\nFor·detailed·information·about·all·available·parameters,·see·[Analysis·Parameters](/analysis/analysis-parameters/).\n\n[[warning]]\n|··The·"begin"·step·will·modify·your·build·like·this:\n|·*·the·active·`CodeAnalysisRuleSet`·will·be·updated·to·match·the·{instance}·quality·profile\n|·*·`WarningsAsErrors`·will·be·turned·off\n|\n|·If·your·build·process·cannot·tolerate·these·changes·we·recommend·creating·a·second·build·job·for·{instance}·analysis.\n\n###·Build\nBetween·the·`begin`·and·`end`·steps,·you·need·to·build·your·project,·execute·tests·and·generate·code·coverage·data.·This·part·is·specific·to·your·needs·and·it·is·not·detailed·here.\n\n###·End\nThe·end·step·is·executed·when·you·add·the·"end"·command·line·argument.·It·cleans·the·MSBuild/dotnet·build·hooks,·collects·the·analysis·data·generated·by·the·build,·the·test·results,·the·code·coverage·and·then·uploads·everything·to·{instance}\n\nThere·are·only·two·additional·arguments·that·are·allowed·for·the·end·step:\n\nParameter|Description\n---|---\n`/d:sonar.login=<token>·or·<username>`|·This·argument·is·required·if·it·was·added·to·the·begin·step.\n`/d:sonar.password=<password>`|·This·argument·is·required·if·it·was·added·to·the·begin·step·and·you·are·not·using·an·authentication·token.\n\n###·Known·Limitations\n\n*·MSBuild·versions·older·than·14·are·not·supported.\n*·Web·Application·projects·are·supported.·Legacy·Web·Site·projects·are·not.\n*·Projects·targeting·multiple·frameworks·and·using·preprocessor·directives·could·have·slightly·inaccurate·metrics·(lines·of·code,·complexity,·etc.)·because·the·metrics·are·calculated·only·from·the·first·of·the·built·targets.\n\n##·Code·Coverage\n\nIn·a·Azure·DevOps·/·TFS·environment,·test·files·are·automatically·retrieved·following·this·search\n*·Search·for·.trx·files·in·any·TestResults·folder·located·under·the·$Build.SourcesDirectory·path\n*·If·not·found,·then·a·fallback·search·is·made·against·$Agent.TempDirectory\n\nOnce·trx·files·have·been·found,·their·`.coverage`·counterpart·are·searched·as·well·and·the·scanner·tries·to·convert·them·to·`.coveragexml`·files·that·will·be·uploaded·to·{instance}.\nCodeCoverage.exe·tool·is·used·for·that,·and·the·scanner·also·needs·to·find·a·path·to·that·tool,·following·this·search·path\n*·Search·for·the·presence·of·`VsTestToolsInstallerInstalledToolLocation`·environment·variable,·set·by·the·VsTestToolsPlatformInstaller·task·or·by·the·user\n*·If·not·found,·search·for·either·the·presence·of·that·tool·in·well-known·installation·path,·or·via·the·registry.\n\nAs·stated·above,·this·will·work·only·with·the·.NET·4.6·flavor·of·the·Scanner.\n\n##·Excluding·projects·from·analysis\n\nSome·project·types,·such·as·[Microsoft·Fakes](https://msdn.microsoft.com/en-us/library/hh549175.aspx),·are·automatically·excluded·from·analysis.·To·manually·exclude·a·different·type·of·project·from·the·analysis,·place·the·following·in·its·.xxproj·file.\n\n```xml\n\x3c!--·in·.csproj·--\x3e\n<PropertyGroup>\n··\x3c!--·Exclude·the·project·from·analysis·--\x3e\n··<SonarQubeExclude>true</SonarQubeExclude>\n</PropertyGroup>\n```\n\n##·Advanced·topics\n\n**Analyzing·MSBuild·12·projects·with·MSBuild·14**··\nThe·Sonar·Scanner·for·.NET·requires·your·project·to·be·built·with·MSBuild·14.0.·We·recommend·installing·Visual·Studio·2015·update·3·or·later·on·the·analysis·machine·in·order·to·benefit·from·the·integration·and·features·provided·with·the·Visual·Studio·ecosystem·(VSTest,·MSTest·unit·tests,·etc.).\n\nProjects·targeting·older·versions·of·the·.NET·Framework·can·be·built·using·MSBuild·14.0·by·setting·the·"TargetFrameworkVersion"·MSBuild·property·as·documented·by·Microsoft:\n\n*·[How·to:·Target·a·Version·of·the·.NET·Framework](https://msdn.microsoft.com/en-us/library/bb398202.aspx)\n*·[MSBuild·Target·Framework·and·Target·Platform](https://msdn.microsoft.com/en-us/library/hh264221.aspx)\n\nIf·you·do·not·want·to·switch·your·production·build·to·MSBuild·14.0,·you·can·set·up·a·separate·build·dedicated·to·the·{instance}·analysis.\n\n**Detection·of·test·projects**\n\nYou·can·read·a·full·description·on·that·subject·on·our·wiki·[here](https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects).\n\n**Per-project·analysis·parameters**\nSome·analysis·parameters·can·be·set·for·a·single·MSBuild·project·by·adding·them·to·its·.csproj·file.\n\n```xml\n\x3c!--·in·.csproj·--\x3e\n<ItemGroup>\n··<SonarQubeSetting·Include="sonar.stylecop.projectFilePath">\n····<Value>$(MSBuildProjectFullPath)</Value>\n··</SonarQubeSetting>\n</ItemGroup>\n```\n\n**Analyzing·languages·other·than·C#·and·VB**\n\nBy·default,·SonarScanner·for·.NET·will·only·analyze·C#·and·VB·files·in·your·project.·To·enable·the·analysis·of·other·types·of·files,·these·files·must·be·listed·in·the·MSBuild·project·file·(the·`.csproj`·or·`.vbproj`·file).\n\nMore·specifically,·any·files·included·by·an·element·of·one·of·the·`ItemTypes`·in\n[this·list](https://github.com/SonarSource/sonar-scanner-msbuild/blob/master/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets#L112)\nwill·be·analyzed·automatically.·For·example,·the·following·line·in·your·`.csproj`·or·`.vbproj`·file\n\n```\n<Content·Include="foo\\bar\\*.js"·/>\n```\n\nwill·enable·the·analysis·of·all·JS·files·in·the·directory·`foo\\bar`·because·`Content`·is·one·of·the·`ItemTypes`·whose·includes·are·automatically·analyzed.\n\nYou·can·also·add·`ItemTypes`·to·the·default·list·by·following·the·directions·[here](https://github.com/SonarSource/sonar-scanner-msbuild/blob/master/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets#L75).\n\nYou·can·check·which·files·the·scanner·will·analyze·by·looking·in·the·file·.sonarqube\\out\\sonar-project.properties·after·MSBuild·has·finished.\n\n**Using·SonarScanner·for·.NET·with·a·Proxy**··\nOn·build·machines·that·connect·to·the·Internet·through·a·proxy·server·you·might·experience·difficulties·connecting·to·{instance}.·To·instruct·the·Java·VM·to·use·the·system·proxy·settings,·you·need·to·set·the·following·environment·variable·before·running·the·SonarScanner·for·.NET:\n\n```bash\nSONAR_SCANNER_OPTS·=·"-Djava.net.useSystemProxies=true"\n```\n\nTo·instruct·the·Java·VM·to·use·specific·proxy·settings·or·when·there·is·no·system-wide·configuration·use·the·following·value:\n\n```bash\nSONAR_SCANNER_OPTS·=·"-Dhttp.proxyHost=yourProxyHost·-Dhttp.proxyPort=yourProxyPort"\n```\nWhere·_yourProxyHost_·and·_yourProxyPort_·are·the·hostname·and·the·port·of·your·proxy·server.·There·are·additional·proxy·settings·for·HTTPS,·authentication·and·exclusions·that·could·be·passed·to·the·Java·VM.·For·more·information·see·the·following·article:·https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html.\n\nHTTP_PROXY,·HTTPS_PROXY,·ALL_PROXY·and·NO_PROXY·will·be·automatically·recognized·and·use·to·make·call·against·{instance}.·The·Scanner·for·.NET·makes·HTTP·calls,·independant·from·the·settings·above·concerning·the·Java·VM,·to·fetch·the·Quality·Profile·and·other·useful·settings·for·the·"end"·step.\n\n##·Known·issues\n\n**I·have·multiple·builds·in·the·same·pipeline,·each·of·them·getting·analyzed·even·if·the·Run·Code·Analysis·has·already·been·executed**\n\nWe·don\'t·uninstall·the·global·`ImportBefore`·targets·to·support·concurrent·analyses·on·the·same·machine.·Main·effect·is·that·if·you·build·a·solution·where·a·.sonarqube·folder·is·located·nearby,·then·the·sonar-dotnet·analyzer·will·be·executed·along·your·build·task.\n\nTo·avoid·that,·you·can·disable·the·targets·file·by·adding·a·build·parameter:\n```\nmsbuild·/p:SonarQubeTargetsImported=true\ndotnet·build·-p:SonarQubeTargetsImported=true\n```\n' |
703 | ············},·{ | 703 | ············},·{ |
704 | ················path:·"analysis/scan/sonarscanner", | 704 | ················path:·"analysis/scan/sonarscanner", |
705 | ················content:·'---\ntitle:·SonarScanner\nurl:·/analysis/scan/sonarscanner/\n---\n\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey="scannercli"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\nThe·SonarScanner·is·the·scanner·to·use·when·there·is·no·specific·scanner·for·your·build·system.\n\n##·Configuring·your·project\nCreate·a·configuration·file·in·your·project\'s·root·directory·called·`sonar-project.properties`\n\n```\n#·must·be·unique·in·a·given·SonarQube·instance\nsonar.projectKey=my:project\n\n#·---·optional·properties·---\n\n#·defaults·to·project·key\n#sonar.projectName=My·project\n#·defaults·to·\'not·provided\'\n#sonar.projectVersion=1.0\n·\n#·Path·is·relative·to·the·sonar-project.properties·file.·Defaults·to·.\n#sonar.sources=.\n·\n#·Encoding·of·the·source·code.·Default·is·default·system·encoding\n#sonar.sourceEncoding=UTF-8\n```\n\n##·Running·SonarScanner·from·the·zip·file\nTo·run·SonarScanner·from·the·zip·file,·follow·these·steps:\n\n1.·Expand·the·downloaded·file·into·the·directory·of·your·choice.·We\'ll·refer·to·it·as·`$install_directory`·in·the·next·steps.\n1.·Update·the·global·settings·to·point·to·your·SonarQube·server·by·editing·`$install_directory/conf/sonar-scanner.properties`:\n```\n#-----·Default·SonarQube·server\n#sonar.host.url=http://localhost:9000\n```\n1.·Add·the·`$install_directory/bin`·directory·to·your·path.\n1.·Verify·your·installation·by·opening·a·new·shell·and·executing·the·command·`sonar-scanner·-h`·(`sonar-scanner.bat·-h`·on·Windows).·You·should·get·output·like·this:\n\n···```\n···usage:·sonar-scanner·[options]\n··\n···Options:\n·····-D,--define·<arg>·····Define·property\n·····-h,--help·············Display·help·information\n·····-v,--version··········Display·version·information\n·····-X,--debug············Produce·execution·debug·output\n···```\nIf·you·need·more·debug·information,·you·can·add·one·of·the·following·to·your·command·line:·`-X`,·`--verbose`,·or·`-Dsonar.verbose=true`.\n\n1.·Run·the·following·command·from·the·project·base·directory·to·launch·analysis·and·pass·your·[authentication·token](/user-guide/user-token/):··\n`sonar-scanner·-Dsonar.login=myAuthenticationToken`\n\n##·Running·SonarScanner·from·the·Docker·image\nTo·scan·using·the·SonarScanner·Docker·image,·use·the·following·command:\n\n```\ndocker·run·\\\n····--rm·\\\n····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"·\\\n····-e·SONAR_LOGIN="myAuthenticationToken"·\\\n····-v·"${YOUR_REPO}:/usr/src"·\\\n····sonarsource/sonar-scanner-cli\n```\n\n##·Scanning·C,·C++,·or·ObjectiveC·Projects\nScanning·projects·that·contain·C,·C++,·or·ObjectiveC·code·requires·some·additional·analysis·steps.·You·can·find·full·details·on·the·[C/C++/Objective-C](/analysis/languages/cfamily/)·language·page.\n\n##·Sample·Projects\nTo·help·you·get·started,·simple·project·samples·are·available·for·most·languages·on·GitHub.·They·can·be·[browsed](https://github.com/SonarSource/sonar-scanning-examples)·or·[downloaded](https://github.com/SonarSource/sonar-scanning-examples/archive/master.zip).·You\'ll·find·them·filed·under·sonarqube-scanner/src.\n\n##·Alternatives·to·sonar-project.properties\nIf·a·sonar-project.properties·file·cannot·be·created·in·the·root·directory·of·the·project,·there·are·several·alternatives:\n\n*·The·properties·can·be·specified·directly·through·the·command·line.·Ex:\n```\nsonar-scanner·-Dsonar.projectKey=myproject·-Dsonar.sources=src1\n```\n*·The·property·project.settings·can·be·used·to·specify·the·path·to·the·project·configuration·file·(this·option·is·incompatible·with·the·`sonar.projectBaseDir`·property).·Ex:\n```\nsonar-scanner·-Dproject.settings=../myproject.properties\n```\n*·The·root·folder·of·the·project·to·analyze·can·be·set·through·the·`sonar.projectBaseDir`·property·since·SonarScanner·2.4.·This·folder·must·contain·a·`sonar-project.properties`·file·if·`sonar.projectKey`·is·not·specified·on·the·command·line.\nAdditional·analysis·parameters·can·be·defined·in·this·project·configuration·file·or·through·command-line·parameters.·\n\n##·Alternate·Analysis·Directory\nIf·the·files·to·be·analyzed·are·not·in·the·directory·where·the·analysis·starts·from,·use·the·`sonar.projectBaseDir`·property·to·move·analysis·to·a·different·directory.·E.G.·analysis·begins·from·`jenkins/jobs/myjob/workspace`·but·the·files·to·be·analyzed·are·in·`ftpdrop/cobol/project1`.\nThis·is·configured·in·`sonar-project.properties`·as·follows:\n```\nsonar.projectBaseDir=/home/ftpdrop/cobol/project1\nsonar.sources=src\nsonar.cobol.copy.directories=/copy\n```\n\n[[info]]\n|·You·can·configure·more·parameters.·See·[Analysis·Parameters](/analysis/analysis-parameters/)·for·details.\n\n##·Advanced·Docker·Configuration\n\nThe·following·sections·offer·advanced·configuration·options·when·running·the·SonarScanner·with·Docker.·Click·the·headings·to·expand·the·instructions.\n\n[[collapse]]\n|·##·Running·as·a·non-root·user\n|·You·can·run·the·Docker·image·as·a·non-root·user·using·the·`--user`·option.·For·example,·to·run·as·the·current·user:\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····--user="$(id·-u):$(id·-g)"·\\\n|·····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"··\\\n|·····-v·"${YOUR_REPO}:/usr/src"·\\\n|·····sonarsource/sonar-scanner-cli\n|·```\n|·[[warning]]\n|·|When·running·the·container·as·a·non-root·user·you·have·to·make·sure·the·user·has·read·and·write·access·to·the·directories·you·are·mounting·(like·your·source·code·or·scanner·cache·directory),·otherwise·you·may·encounter·permission-related·problems.··\n\n[[collapse]]\n|·##·Caching·scanner·files\n|·To·prevent·SonarScanner·from·re-downloading·language·analyzers·each·time·you·run·a·scan,·you·can·mount·a·directory·where·the·scanner·stores·the·downloads·so·that·the·downloads·are·reused·between·scanner·runs.·On·some·CI·systems,·you·also·need·to·add·this·directory·to·your·CI·cache·configuration.·\n|\n|·The·following·command·will·store·and·use·cache·between·runs:\n|\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····-v·${YOUR_CACHE_DIR}:/opt/sonar-scanner/.sonar/cache·\\\n|·····-v·${YOUR_REPO}:/usr/src·\\\n|·····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"·\\\n|·····sonarsource/sonar-scanner-cli\n|·```\n|\n|·You·can·also·change·the·location·of·where·the·scanner·puts·the·downloads·with·the·`SONAR_USER_HOME`·environment·variable.\n\n[[collapse]]\n|·##·Using·self-signed·certificates\n|·If·you·need·to·configure·a·self-signed·certificate·for·the·scanner·to·communicate·with·your·SonarQube·instance,·we·recommend·using·the·OpenJDK·provided·with·the·`sonarsource/sonar-scanner-cli`·image.·To·do·this,·follow·these·steps:·\n|\n|·1.·Extract·the·`cacerts`·file·from·OpenJDK·from·the·`sonarsource/sonar-scanner-cli`·image:\n|\n|·```\n|·docker·pull·sonarsource/sonar-scanner-cli\n|·docker·run·\\\n|·····--rm·\\\n|·····--entrypoint·cat·sonarsource/sonar-scanner-cli·/opt/java/openjdk/lib/security/cacerts·>·cacerts\n|·```\n|\n|·2.·Add·your·certificate·to·the·exported·`cacerts`·file.·Assuming·your·certificate·file·is·named·`mycert.cer`·and·it\'s·in·your·current·local·directory:\n|\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····-v·`pwd`:/tmp/certs·\\\n|·····sonarsource/sonar-scanner-cli·\\\n|·····bash·-c·\'cd·/tmp/certs·&&·keytool·-keystore·cacerts·-storepass·changeit·-noprompt·-trustcacerts·-importcert·-alias·mycert·-file·mycert.cer\'\n|·```\n|\n|·3.·Mount·the·`cacerts`·file·that·you\'ve·prepared·in·your·target·container:\n|·\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"·\\\n|·····-v·`pwd`/cacerts:/opt/java/openjdk/lib/security/cacerts·\\\n|·····sonarsource/sonar-scanner-cli\n|·```\n|\n|·Alternatively,·you·can·create·your·own·container·that·includes·the·modified·`cacerts`·file.·Create·a·`Dockerfile`·with·the·following·contents:\n|\n|·```\n|·FROM·sonarsource/sonar-scanner-cli\n|·COPY·cacerts·/opt/java/openjdk/lib/security/cacerts\n|·```\n|\n|·Then,·assuming·both·the·`cacerts`·and·`Dockerfile`·are·in·the·current·directory,·create·the·new·image·with·a·command·such·as:\n|·```\n|·docker·build·--tag·our-custom/sonar-scanner-cli·.\n|·```\n|\n\n##·Troubleshooting\n**Java·heap·space·error·or·java.lang.OutOfMemoryError**··\nIncrease·the·memory·via·the·`SONAR_SCANNER_OPTS`·environment·variable·when·running·the·scanner·from·a·zip·file:\n```\nexport·SONAR_SCANNER_OPTS="-Xmx512m"\n```\nIn·Windows·environments,·avoid·the·double-quotes,·since·they·get·misinterpreted·and·combine·the·two·parameters·into·a·single·one.\n```\nset·SONAR_SCANNER_OPTS=-Xmx512m\n```\n\n**Unsupported·major.minor·version**··\nUpgrade·the·version·of·Java·being·used·for·analysis·or·use·one·of·the·native·package·(that·embed·its·own·Java·runtime).\n\n**Property·missing:·`sonar.cs.analyzer.projectOutPaths\'.·No·protobuf·files·will·be·loaded·for·this·project.**··\nScanner·CLI·is·not·able·to·analyze·.NET·projects.·Please,·use·the·SonarScanner·for·.NET.·If·you·are·running·the·SonarScanner·for·.NET,·ensure·that·you·are·not·hitting·a·known·limitation.\n' | 705 | ················content:·'---\ntitle:·SonarScanner\nurl:·/analysis/scan/sonarscanner/\n---\n\n\x3c!--·static·--\x3e\n<update-center·updatecenterkey="scannercli"></update-center>\n\x3c!--·/static·--\x3e\n\x3c!--·embedded·--\x3e\n[[info]]\n|·See·the·[online·documentation](https://redirect.sonarsource.com/doc/download-scanner.html)·to·get·more·details·on·the·latest·version·of·the·scanner·and·how·to·download·it.\n\x3c!--·/embedded·--\x3e\n\nThe·SonarScanner·is·the·scanner·to·use·when·there·is·no·specific·scanner·for·your·build·system.\n\n##·Configuring·your·project\nCreate·a·configuration·file·in·your·project\'s·root·directory·called·`sonar-project.properties`\n\n```\n#·must·be·unique·in·a·given·SonarQube·instance\nsonar.projectKey=my:project\n\n#·---·optional·properties·---\n\n#·defaults·to·project·key\n#sonar.projectName=My·project\n#·defaults·to·\'not·provided\'\n#sonar.projectVersion=1.0\n·\n#·Path·is·relative·to·the·sonar-project.properties·file.·Defaults·to·.\n#sonar.sources=.\n·\n#·Encoding·of·the·source·code.·Default·is·default·system·encoding\n#sonar.sourceEncoding=UTF-8\n```\n\n##·Running·SonarScanner·from·the·zip·file\nTo·run·SonarScanner·from·the·zip·file,·follow·these·steps:\n\n1.·Expand·the·downloaded·file·into·the·directory·of·your·choice.·We\'ll·refer·to·it·as·`$install_directory`·in·the·next·steps.\n1.·Update·the·global·settings·to·point·to·your·SonarQube·server·by·editing·`$install_directory/conf/sonar-scanner.properties`:\n```\n#-----·Default·SonarQube·server\n#sonar.host.url=http://localhost:9000\n```\n1.·Add·the·`$install_directory/bin`·directory·to·your·path.\n1.·Verify·your·installation·by·opening·a·new·shell·and·executing·the·command·`sonar-scanner·-h`·(`sonar-scanner.bat·-h`·on·Windows).·You·should·get·output·like·this:\n\n···```\n···usage:·sonar-scanner·[options]\n··\n···Options:\n·····-D,--define·<arg>·····Define·property\n·····-h,--help·············Display·help·information\n·····-v,--version··········Display·version·information\n·····-X,--debug············Produce·execution·debug·output\n···```\nIf·you·need·more·debug·information,·you·can·add·one·of·the·following·to·your·command·line:·`-X`,·`--verbose`,·or·`-Dsonar.verbose=true`.\n\n1.·Run·the·following·command·from·the·project·base·directory·to·launch·analysis·and·pass·your·[authentication·token](/user-guide/user-token/):··\n`sonar-scanner·-Dsonar.login=myAuthenticationToken`\n\n##·Running·SonarScanner·from·the·Docker·image\nTo·scan·using·the·SonarScanner·Docker·image,·use·the·following·command:\n\n```\ndocker·run·\\\n····--rm·\\\n····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"·\\\n····-e·SONAR_LOGIN="myAuthenticationToken"·\\\n····-v·"${YOUR_REPO}:/usr/src"·\\\n····sonarsource/sonar-scanner-cli\n```\n\n##·Scanning·C,·C++,·or·ObjectiveC·Projects\nScanning·projects·that·contain·C,·C++,·or·ObjectiveC·code·requires·some·additional·analysis·steps.·You·can·find·full·details·on·the·[C/C++/Objective-C](/analysis/languages/cfamily/)·language·page.\n\n##·Sample·Projects\nTo·help·you·get·started,·simple·project·samples·are·available·for·most·languages·on·GitHub.·They·can·be·[browsed](https://github.com/SonarSource/sonar-scanning-examples)·or·[downloaded](https://github.com/SonarSource/sonar-scanning-examples/archive/master.zip).·You\'ll·find·them·filed·under·sonarqube-scanner/src.\n\n##·Alternatives·to·sonar-project.properties\nIf·a·sonar-project.properties·file·cannot·be·created·in·the·root·directory·of·the·project,·there·are·several·alternatives:\n\n*·The·properties·can·be·specified·directly·through·the·command·line.·Ex:\n```\nsonar-scanner·-Dsonar.projectKey=myproject·-Dsonar.sources=src1\n```\n*·The·property·project.settings·can·be·used·to·specify·the·path·to·the·project·configuration·file·(this·option·is·incompatible·with·the·`sonar.projectBaseDir`·property).·Ex:\n```\nsonar-scanner·-Dproject.settings=../myproject.properties\n```\n*·The·root·folder·of·the·project·to·analyze·can·be·set·through·the·`sonar.projectBaseDir`·property·since·SonarScanner·2.4.·This·folder·must·contain·a·`sonar-project.properties`·file·if·`sonar.projectKey`·is·not·specified·on·the·command·line.\nAdditional·analysis·parameters·can·be·defined·in·this·project·configuration·file·or·through·command-line·parameters.·\n\n##·Alternate·Analysis·Directory\nIf·the·files·to·be·analyzed·are·not·in·the·directory·where·the·analysis·starts·from,·use·the·`sonar.projectBaseDir`·property·to·move·analysis·to·a·different·directory.·E.G.·analysis·begins·from·`jenkins/jobs/myjob/workspace`·but·the·files·to·be·analyzed·are·in·`ftpdrop/cobol/project1`.\nThis·is·configured·in·`sonar-project.properties`·as·follows:\n```\nsonar.projectBaseDir=/home/ftpdrop/cobol/project1\nsonar.sources=src\nsonar.cobol.copy.directories=/copy\n```\n\n[[info]]\n|·You·can·configure·more·parameters.·See·[Analysis·Parameters](/analysis/analysis-parameters/)·for·details.\n\n##·Advanced·Docker·Configuration\n\nThe·following·sections·offer·advanced·configuration·options·when·running·the·SonarScanner·with·Docker.·Click·the·headings·to·expand·the·instructions.\n\n[[collapse]]\n|·##·Running·as·a·non-root·user\n|·You·can·run·the·Docker·image·as·a·non-root·user·using·the·`--user`·option.·For·example,·to·run·as·the·current·user:\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····--user="$(id·-u):$(id·-g)"·\\\n|·····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"··\\\n|·····-v·"${YOUR_REPO}:/usr/src"·\\\n|·····sonarsource/sonar-scanner-cli\n|·```\n|·[[warning]]\n|·|When·running·the·container·as·a·non-root·user·you·have·to·make·sure·the·user·has·read·and·write·access·to·the·directories·you·are·mounting·(like·your·source·code·or·scanner·cache·directory),·otherwise·you·may·encounter·permission-related·problems.··\n\n[[collapse]]\n|·##·Caching·scanner·files\n|·To·prevent·SonarScanner·from·re-downloading·language·analyzers·each·time·you·run·a·scan,·you·can·mount·a·directory·where·the·scanner·stores·the·downloads·so·that·the·downloads·are·reused·between·scanner·runs.·On·some·CI·systems,·you·also·need·to·add·this·directory·to·your·CI·cache·configuration.·\n|\n|·The·following·command·will·store·and·use·cache·between·runs:\n|\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····-v·${YOUR_CACHE_DIR}:/opt/sonar-scanner/.sonar/cache·\\\n|·····-v·${YOUR_REPO}:/usr/src·\\\n|·····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"·\\\n|·····sonarsource/sonar-scanner-cli\n|·```\n|\n|·You·can·also·change·the·location·of·where·the·scanner·puts·the·downloads·with·the·`SONAR_USER_HOME`·environment·variable.\n\n[[collapse]]\n|·##·Using·self-signed·certificates\n|·If·you·need·to·configure·a·self-signed·certificate·for·the·scanner·to·communicate·with·your·SonarQube·instance,·we·recommend·using·the·OpenJDK·provided·with·the·`sonarsource/sonar-scanner-cli`·image.·To·do·this,·follow·these·steps:·\n|\n|·1.·Extract·the·`cacerts`·file·from·OpenJDK·from·the·`sonarsource/sonar-scanner-cli`·image:\n|\n|·```\n|·docker·pull·sonarsource/sonar-scanner-cli\n|·docker·run·\\\n|·····--rm·\\\n|·····--entrypoint·cat·sonarsource/sonar-scanner-cli·/opt/java/openjdk/lib/security/cacerts·>·cacerts\n|·```\n|\n|·2.·Add·your·certificate·to·the·exported·`cacerts`·file.·Assuming·your·certificate·file·is·named·`mycert.cer`·and·it\'s·in·your·current·local·directory:\n|\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····-v·`pwd`:/tmp/certs·\\\n|·····sonarsource/sonar-scanner-cli·\\\n|·····bash·-c·\'cd·/tmp/certs·&&·keytool·-keystore·cacerts·-storepass·changeit·-noprompt·-trustcacerts·-importcert·-alias·mycert·-file·mycert.cer\'\n|·```\n|\n|·3.·Mount·the·`cacerts`·file·that·you\'ve·prepared·in·your·target·container:\n|·\n|·```\n|·docker·run·\\\n|·····--rm·\\\n|·····-e·SONAR_HOST_URL="http://${SONARQUBE_URL}"·\\\n|·····-v·`pwd`/cacerts:/opt/java/openjdk/lib/security/cacerts·\\\n|·····sonarsource/sonar-scanner-cli\n|·```\n|\n|·Alternatively,·you·can·create·your·own·container·that·includes·the·modified·`cacerts`·file.·Create·a·`Dockerfile`·with·the·following·contents:\n|\n|·```\n|·FROM·sonarsource/sonar-scanner-cli\n|·COPY·cacerts·/opt/java/openjdk/lib/security/cacerts\n|·```\n|\n|·Then,·assuming·both·the·`cacerts`·and·`Dockerfile`·are·in·the·current·directory,·create·the·new·image·with·a·command·such·as:\n|·```\n|·docker·build·--tag·our-custom/sonar-scanner-cli·.\n|·```\n|\n\n##·Troubleshooting\n**Java·heap·space·error·or·java.lang.OutOfMemoryError**··\nIncrease·the·memory·via·the·`SONAR_SCANNER_OPTS`·environment·variable·when·running·the·scanner·from·a·zip·file:\n```\nexport·SONAR_SCANNER_OPTS="-Xmx512m"\n```\nIn·Windows·environments,·avoid·the·double-quotes,·since·they·get·misinterpreted·and·combine·the·two·parameters·into·a·single·one.\n```\nset·SONAR_SCANNER_OPTS=-Xmx512m\n```\n\n**Unsupported·major.minor·version**··\nUpgrade·the·version·of·Java·being·used·for·analysis·or·use·one·of·the·native·package·(that·embed·its·own·Java·runtime).\n\n**Property·missing:·`sonar.cs.analyzer.projectOutPaths\'.·No·protobuf·files·will·be·loaded·for·this·project.**··\nScanner·CLI·is·not·able·to·analyze·.NET·projects.·Please,·use·the·SonarScanner·for·.NET.·If·you·are·running·the·SonarScanner·for·.NET,·ensure·that·you·are·not·hitting·a·known·limitation.\n' |
706 | ············},·{ | 706 | ············},·{ |
707 | ················path:·"analysis/scm-integration", | 707 | ················path:·"analysis/scm-integration", |
708 | ················content:·"---\ntitle:·SCM·Integration\nurl:·/analysis/scm-integration/\n---\n\nCollecting·SCM·data·during·code·analysis·can·unlock·a·number·of·SonarQube·features:\n\n*·Automatic·Issue·Assignment\n*·code·annotation·(blame·data)·in·the·Code·Viewer\n*·SCM-driven·detection·of·new·code·(to·help·with·[Clean·as·You·Code](/user-guide/clean-as-you-code/)).·Without·SCM·data,·SonarQube·determines·new·code·using·analysis·dates·(to·timestamp·modification·of·lines).\n\nSCM·integration·requires·support·for·your·individual·SCM·provider.·Git·and·SVN·are·supported·by·default.·For·other·SCM·providers,·see·the·Marketplace.\n\nIf·need·be,·you·can·toggle·it·off·at·global·level·via·administration·settings·and·at·a·project·level·via·project·settings.\n\n##·Git\n[Git](http://www.git-scm.com/)·integration·is·supported·out·of·the·box·with·a·pure·Java·implementation·so·there's·no·need·to·have·Git·command·line·tool·installed·on·the·machine·where·analysis·is·performed.\n\nAuto-detection·of·Git·during·analysis·will·happen·if·there·is·a·.git·folder·in·the·project·root·directory·or·in·one·of·its·parent·folders.·Otherwise·you·can·force·the·provider·using·`-Dsonar.scm.provider=git`.·A·full·clone·is·required·for·this·integration·to·be·able·to·collect·the·required·blame·information·(see·Known·Issues).·If·a·shallow·clone·is·detected,·a·warning·will·be·logged·and·no·attempt·will·be·made·to·retrieve·blame·information.\n\nGit·integration·uses·[JGit](https://www.eclipse.org/jgit/).·JGit·is·a·pure·Java·implementation·of·the·Git·client.\n\n###·Known·Issues\n\n*·Git·doesn't·consider·old·\"Mac\"·line·ends·(CR)·as·new·lines.·As·a·result·the·blame·operation·will·contain·fewer·lines·than·expected·by·SonarQube·and·analysis·will·fail.·The·solution·is·to·fix·line·ends·to·use·either·Windows·(CR/LF)·or·Unix·(LF)·line·ends.\n*·JGit·doesn't·support·.mailmap·file·to·\"clean\"·email·adress·during·the·blame\n*·\"Missing·blame·information...\"·and·\"Could·not·find·ref...\"·can·be·caused·by·checking·out·with·a·partial·/·shallow·clone,·or·using·Git·submodules.\n\n###·How·to·investigate·error·during·blame·(only·possible·on·Unix/Linux)?\n\nIf·you·get·an·error·when·blame·is·executed·on·a·file,·it·may·be·a·limitation·or·a·bug·in·JGit.·To·confirm·please·follow·these·steps:\n\n1.·Download·the·standalone·JGit·command·line·distribution\n\n2.·Try·to·execute·the·blame·command·on·the·offending·file:··\n····`chmod·+x·/path/to/org.eclipse.jgit.pgm-4.9.0.201710071750-r.sh·/path/to/org.eclipse.jgit.pgm-4.9.0.201710071750-r.sh·blame·-w·/path/to/offending/file`\n\n3.·If·you·get·the·same·error·as·during·analysis,·then·this·really·looks·like·a·bug·in·JGit·(especially·if·you·don't·have·an·issue·with·the·native·git·command·line·tool).·Please·try·to·do·the·previous·steps·with·latest·version·of·JGit·and·report·all·information·to·the·[SonarQube·Community·Forum](https://community.sonarsource.com/).\n\n##·Subversion\n[Subversion](https://subversion.apache.org/)·integration·is·supported·out·of·the·box·for·Subversion·1.6·to·1.9.x.\n\nAuto-detection·of·SVN·during·analysis·will·happen·if·there·is·a·`.svn`·folder·somewhere·in·the·parent·hierarchy·of·the·project·root.·Otherwise·you·can·force·the·provider·using·`-Dsonar.scm.provider=svn`·on·the·analysis·command·line.\n\n###·Known·issues\nIf·you·get·errors·like:\n\n`Caused·by:·org.tmatesoft.svn.core.SVNException:·svn:·E200007:·Retrieval·of·mergeinfo·unsupported·by·'https://pmd.svn.sourceforge.net/svnroot/pmd/trunk/pmd/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java';`\nIt·means·the·SVN·server·is·not·advertising·the·'mergeinfo'·capability.·You·can·check·the·advertised·capabilities·by·simply·connecting·to·it:\n\n`telnet·<svn_server>·3690`\nOften·this·is·because·your·SVN·server·is·not·>=·1.5·or·your·project·was·not·properly·migrated·after·a·server·upgrade.·It·could·also·be·a·misconfiguration·of·the·server.\n\nYou·should·try·to·run·svnadmin·upgrade·**on·the·server**.·For·more·information,·please·read·https://subversion.apache.org/docs/release-notes/1.5.html#repos-upgrades.\n\n" | 708 | ················content:·"---\ntitle:·SCM·Integration\nurl:·/analysis/scm-integration/\n---\n\nCollecting·SCM·data·during·code·analysis·can·unlock·a·number·of·SonarQube·features:\n\n*·Automatic·Issue·Assignment\n*·code·annotation·(blame·data)·in·the·Code·Viewer\n*·SCM-driven·detection·of·new·code·(to·help·with·[Clean·as·You·Code](/user-guide/clean-as-you-code/)).·Without·SCM·data,·SonarQube·determines·new·code·using·analysis·dates·(to·timestamp·modification·of·lines).\n\nSCM·integration·requires·support·for·your·individual·SCM·provider.·Git·and·SVN·are·supported·by·default.·For·other·SCM·providers,·see·the·Marketplace.\n\nIf·need·be,·you·can·toggle·it·off·at·global·level·via·administration·settings·and·at·a·project·level·via·project·settings.\n\n##·Git\n[Git](http://www.git-scm.com/)·integration·is·supported·out·of·the·box·with·a·pure·Java·implementation·so·there's·no·need·to·have·Git·command·line·tool·installed·on·the·machine·where·analysis·is·performed.\n\nAuto-detection·of·Git·during·analysis·will·happen·if·there·is·a·.git·folder·in·the·project·root·directory·or·in·one·of·its·parent·folders.·Otherwise·you·can·force·the·provider·using·`-Dsonar.scm.provider=git`.·A·full·clone·is·required·for·this·integration·to·be·able·to·collect·the·required·blame·information·(see·Known·Issues).·If·a·shallow·clone·is·detected,·a·warning·will·be·logged·and·no·attempt·will·be·made·to·retrieve·blame·information.\n\nGit·integration·uses·[JGit](https://www.eclipse.org/jgit/).·JGit·is·a·pure·Java·implementation·of·the·Git·client.\n\n###·Known·Issues\n\n*·Git·doesn't·consider·old·\"Mac\"·line·ends·(CR)·as·new·lines.·As·a·result·the·blame·operation·will·contain·fewer·lines·than·expected·by·SonarQube·and·analysis·will·fail.·The·solution·is·to·fix·line·ends·to·use·either·Windows·(CR/LF)·or·Unix·(LF)·line·ends.\n*·JGit·doesn't·support·.mailmap·file·to·\"clean\"·email·adress·during·the·blame\n*·\"Missing·blame·information...\"·and·\"Could·not·find·ref...\"·can·be·caused·by·checking·out·with·a·partial·/·shallow·clone,·or·using·Git·submodules.\n\n###·How·to·investigate·error·during·blame·(only·possible·on·Unix/Linux)?\n\nIf·you·get·an·error·when·blame·is·executed·on·a·file,·it·may·be·a·limitation·or·a·bug·in·JGit.·To·confirm·please·follow·these·steps:\n\n1.·Download·the·standalone·JGit·command·line·distribution\n\n2.·Try·to·execute·the·blame·command·on·the·offending·file:··\n····`chmod·+x·/path/to/org.eclipse.jgit.pgm-4.9.0.201710071750-r.sh·/path/to/org.eclipse.jgit.pgm-4.9.0.201710071750-r.sh·blame·-w·/path/to/offending/file`\n\n3.·If·you·get·the·same·error·as·during·analysis,·then·this·really·looks·like·a·bug·in·JGit·(especially·if·you·don't·have·an·issue·with·the·native·git·command·line·tool).·Please·try·to·do·the·previous·steps·with·latest·version·of·JGit·and·report·all·information·to·the·[SonarQube·Community·Forum](https://community.sonarsource.com/).\n\n##·Subversion\n[Subversion](https://subversion.apache.org/)·integration·is·supported·out·of·the·box·for·Subversion·1.6·to·1.9.x.\n\nAuto-detection·of·SVN·during·analysis·will·happen·if·there·is·a·`.svn`·folder·somewhere·in·the·parent·hierarchy·of·the·project·root.·Otherwise·you·can·force·the·provider·using·`-Dsonar.scm.provider=svn`·on·the·analysis·command·line.\n\n###·Known·issues\nIf·you·get·errors·like:\n\n`Caused·by:·org.tmatesoft.svn.core.SVNException:·svn:·E200007:·Retrieval·of·mergeinfo·unsupported·by·'https://pmd.svn.sourceforge.net/svnroot/pmd/trunk/pmd/src/main/java/net/sourceforge/pmd/AbstractConfiguration.java';`\nIt·means·the·SVN·server·is·not·advertising·the·'mergeinfo'·capability.·You·can·check·the·advertised·capabilities·by·simply·connecting·to·it:\n\n`telnet·<svn_server>·3690`\nOften·this·is·because·your·SVN·server·is·not·>=·1.5·or·your·project·was·not·properly·migrated·after·a·server·upgrade.·It·could·also·be·a·misconfiguration·of·the·server.\n\nYou·should·try·to·run·svnadmin·upgrade·**on·the·server**.·For·more·information,·please·read·https://subversion.apache.org/docs/release-notes/1.5.html#repos-upgrades.\n\n" |
709 | ············},·{ | 709 | ············},·{ |