Analyse a .NET code which is running through groovy script

Hi team,

I’m using the groovy script to build by .NET application. Application is working fine but i’d like to analyse the code through groovy. Can you tell me the process for it ?

Hi @Raghavendra_Rao_Itik,

You’ll need to the use the Scanner for MSBuild to analyse C# or VB.Net code. The scanner is a command line executable so you can use it with any scripting language that can run command line tools. The instructions for using the scanner are here.

Hey Duncan,

Thanks for the reply. Well I’ve already implemented using Pipeline script as below

def sqScannerMsBuildHome = tool 'SonarScannerMSBuild'
                  withSonarQubeEnv('SonarQubeServer') {
                        bat "${sqScannerMsBuildHome}\\SonarScanner.MSBuild.exe begin /key:TEST6 /name:TEST6 /version:TEST_" + BUILD_BRANCH +" /d:sonar.host.url=http://test.com/ /d:sonar.verbose=true"
                        bat 'REM CALL msbuild TEST.API.sln /t:restore TEST.API.sln /p:DeployOnBuild=true /m:4 /p:BuildInParallel=true /p:PublishProfile=FolderProfile /t:Rebuild /p:Configuration=Release'
                        bat 'SET PATH="%ProgramFiles(x86)%\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\";%PATH%'
                        bat 'call dotnet restore'
                        bat 'call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\MSBuild.exe" /t:restore TEST.API.sln /p:DeployOnBuild=true /m:4 /p:BuildInParallel=true /p:PublishProfile=FolderProfile /t:Rebuild /p:Configuration=Release'
                        bat "${sqScannerMsBuildHome}\\SonarScanner.MSBuild.exe end"
                  }

Above code is working fine using Jenkins pipeline script. But now instead of running it from Jenkins pipeline code I’ll running the code build using groovy as below

bat ‘call groovy DevOpsScripts\DevOpsTool.groovy -c “.\Clinical 360 DevOps\JenkinsConfig\Development-compile.xml” -v "’+ BUILD_BRANCH +’"’

In above code Development-compile.xml file consists of just command line codes for building app i.e. MSBuild.

My question is using pipeline script SonarServer is configured in Jenkins and code is running using Jenkins so the server config worked and code got analysed.

But groovy script is not part of Jenkins pipeline. We’re just passing the code along with XML config file which will read the tag with commands and implement it on the source code.

How can i configure it to analyse code.

Sample XML file

    <OperatingSystemCommand dirToRunIn="./OWCA.Clinical360" command="msbuild" timeout="300000">
        <Argument value="OWCA.Clinical360.sln"/>
      
      </OperatingSystemCommand>
</ProcessConfiguration>

@Raghavendra_Rao_Itik, where does the script DevOpsTool.groovy come from? Is it a custom script owned by your company?

@duncanp DevOpsTool.groovy is the custom groovy script that we’ve developed from our end. It just takes the xml config contents and executes it

@Raghavendra_Rao_Itik I’m confused. You’ve correctly set up a Jenkins pipeline so you know which executables to call, the order to call them in, and what the arguments to each executable should be.

What are you asking? What you should put in your Development-compile.xml file, how you should change your DevOpsTool.groovy script, or something else?