0

My test folder is set up as follows:

enter image description here

I have ran source monitor on its own from the command line and it runs to completion successfully and outputs some .xml files that I need for my CI process.

Below is my .proj file that I am trying to run:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Analyze" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
  <MSBuildCommunityTasksPath>.</MSBuildCommunityTasksPath>
</PropertyGroup>
  <Import Project="MSBuild.Community.Tasks.Targets"/>

  <Target Name="Analyze">  
    <Exec Command="sm.exe /C sm-commands.xml"/>

    <XmlRead XPath="//*/metric[@id='M0']" XmlFileName="sm-summary.xml">
      <Output TaskParameter="Value" PropertyName="NumberOfLines" />
    </XmlRead>
    <TeamCityReportStatsValue Key="NumberOfLines" Value="$(NumberOfLines)" />

    <XmlRead XPath="//*/metric[@id='M5']" XmlFileName="sm-summary.xml">
      <Output TaskParameter="Value" PropertyName="MethodsPerClass" />
    </XmlRead>
    <TeamCityReportStatsValue Key="MethodsPerClass" Value="$(MethodsPerClass)" />

    <XmlRead XPath="//*/metric[@id='M7']" XmlFileName="sm-summary.xml">
      <Output TaskParameter="Value" PropertyName="StatementsPerMethod" />
    </XmlRead>
    <TeamCityReportStatsValue Key="StatementsPerMethod" Value="$(StatementsPerMethod)" />

    <XmlRead XPath="//*/metric[@id='M10']" XmlFileName="sm-summary.xml">
      <Output TaskParameter="Value" PropertyName="MaxComplexity" />
    </XmlRead>
    <TeamCityReportStatsValue Key="MaxComplexity" Value="$(MaxComplexity)" />

    <XmlRead XPath="//*/metric[@id='M14']" XmlFileName="sm-summary.xml">
      <Output TaskParameter="Value" PropertyName="AvgComplexity" />
    </XmlRead>
    <TeamCityReportStatsValue Key="AvgComplexity" Value="$(AvgComplexity)" /> 

    </Target>
</Project>

I get the following error:

enter image description here

RESEARCH LINK:Article I am following

IbrarMumtaz
  • 4,235
  • 7
  • 44
  • 63

1 Answers1

1

Exit code 1 is not really helpful. Try prepending your command with start cmd /k (it'll escape MSBuild's sandbox redirect with a new cmd window) and see if it prints anything else. One possibility for ERRORLEVEL 1 is MSBuild closing input stream so if sc.exe is interactive and needs to read anything from the user it would terminate with exit code 1.

Also, after you manually "ran to completion successfully", did you check the exit code with echo %ERRORLEVEL%? It might exit quietly and output some files but still technically fail with a non-0 exit code.

Ilya Kozhevnikov
  • 10,242
  • 4
  • 40
  • 70
  • Let me try that and get back to you. Thanks for answering. – IbrarMumtaz Aug 19 '14 at 10:29
  • I ran the source monitor command manually, works as expected. Exit command is 0. – IbrarMumtaz Aug 19 '14 at 10:51
  • It magically started working now, I tried 'start cmd /k' that got somewhere but the cmd window was stuck open. Looking closely at the command and I think there might have been a typo in there. – IbrarMumtaz Aug 19 '14 at 11:03
  • @IbrarMumtaz yes, that's the goal, `start` would escape the redirect so the input stream won't be closed and `/k` would keep it open so you can read any additional messages if there are any. – Ilya Kozhevnikov Aug 19 '14 at 11:05