pipeline 
{   
    agent 
	{
        node 
		{
            label 'jenkins_homer_agent'
        }                
	}            
    stages 
	{        
        stage('Build') 
		{
            environment
            {
                dotnet ="C:\\Program Files\\dotnet\\"
                
            }	
            steps 
			{     
                  cleanWs()
                  checkout scm
                  bat "dotnet restore Hochbaustatistik.sln"                  
                  bat "\"${tool 'MSBuild17'}\" ${WORKSPACE}\\Hochbaustatistik.sln /t:Restore /t:Rebuild /p:Configuration=Debug"                       
             }
        }     
        stage('Test')
        {
            environment
            {
                dotnet ="C:\\Program Files\\dotnet\\"
            }
            steps
             {
                 catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') 
        	     {                    
				       bat "dotnet test ${WORKSPACE}\\Hochbaustatistik.Testing\\Hochbaustatistik.Testing.csproj /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=..\\..\\coverage.xml /p:Exclude=[Scan2Compress.GUI]*%2c[Scan2Compress.Properties]* --no-build"                   
                 }                
             }               
        }
        stage('SonarQube')
        {     
            environment
            {    
                scannerHome = "C:\\home\\jenkins\\tools\\hudson.plugins.sonar.MsBuildSQRunnerInstallation\\C_sonar-runner"         
                token = 'sqa_sqa_07d4e3802cf6283fc38a002e75bd0a5eb158af87'
                project = 'hochbaustatistik'                                            
            }	
            steps
            {
                bat "${scannerHome}\\SonarScanner.MSBuild.exe begin /k:${project} /d:sonar.token=${token} /d:sonar.verbose=true /d:sonar.cs.opencover.reportsPaths=${WORKSPACE}\\coverage.xml"
                bat "${scannerHome}\\SonarScanner.MSBuild.exe end /d:sonar.token=${token}"
            }            
        }        
    }     
}