Jenkins 工作 dsl 和 MSTest 集成

Jenkins job dsl and MSTest integration

Jenkins Job DSL 插件是一种非常好的方式,可以将 CI 配置存储在 repo 中,并在分支与分支之间进行更改。

问题是 - 是否有一种自然或接近自然的方式来 运行 MSTest 测试、解析结果并显示它们。

现在我进行了一次 powershell 调用,但这只给我日志,而不是 UI 集成。

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

可能有发布者或模板技巧,或者为此编写 JOB DSL 插件的一些技巧


UPD:使用 , jenkins xUnit Plugin and archiveXUnit

的 MSTest 和 VSTest 的最终脚本模板
  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()
          }
        }
      }
    }

使用 PowerShell 步骤是一个好的开始。安装 xUnit Plugin to parse and display the results. It can parse all sorts of test results including MSTest. And you can use the DSL 以配置插件。

示例:

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

它适用于 VSTest,但我不得不最终使用配置块才能在 DSL 作业中使用它。

static Closure useVsTest(List<String> dlls) { return { it / 'builders' << 'org.jenkinsci.plugins.vstest__runner.VsTestBuilder' { vsTestName 'VS 14.0' testFiles dlls.join('\n') settings '' testCaseFilter '' enablecodecoverage false useVsixExtensions true platform 'x86' otherPlatform '' framework 'framework45' otherFramework '' logger 'trx' otherLogger '' cmdLineArgs '/TestAdapterPath:"."' failBuild true } } }