jenkinsjenkins-pluginsmstestjenkins-job-dsljenkins-mstest

Jenkins job dsl and MSTest integration


Jenkins Job DSL plugin is an extremely nice way to store CI config in repo and vary it from branch to branch.

The question is - is there a natural or close to natural way to run MSTest tests, parse results and display them.

Right now I do a powershell call, but that gives me only logs, not UI integration.

def testSomeProjectJob =  job(testSomeProjectJobName) {
    steps { 
      powerShell("& ${vstest} '${root}/SomeProject/SomeProject.Tests/bin/Debug/SomeProject.Tests.dll' ")
    }
}

May be there is a publisher or a trick with templating, or some tips of writing a plugin to JOB DSL for that


UPD: final script template for MSTest and VSTest using @daspilker answer, jenkins xUnit Plugin and archiveXUnit

  job('RunTests') {
      steps {
           // VSTEST
           powerShell("& ${vstest} 'path/to/Tests.dll' /logger:trx ")
           // Or MSBUILD
            powerShell("& ${msbuild} /testcontainer:'path/to/Tests.dll' ")
      }
      publishers {
        archiveXUnit {
          msTest {
            pattern('**/*.trx')
            // deleteOutputFiles()
          }
        }
      }
    }

Solution

  • Using a PowerShell step is a good start. Install the xUnit Plugin to parse and display the results. It can parse all sorts of test results including MSTest. And you can use the DSL to configure the plugin.

    Example:

    job('example') {
      steps {
        powerShell('...')
      }
      publishers {
        archiveXUnit {
          msTest {
            pattern('path/to/test/results')
          }
        }
      }
    }